|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Menu?
If I have a directory with a few text files how can I create a menu that
lists those files and I can open them from that menu, then return to that menu when i've finished with a file? Thanks Rick |
|
#2
|
|||
|
|||
|
Menu?
Rick_C wrote:
If I have a directory with a few text files how can I create a menu that lists those files and I can open them from that menu, then return to that menu when i've finished with a file? In Win2k/XP/Vista this is trivial, type for /? start /? set /? for more information. In pure DS or Win9x this is more complicated. Here one way to do it: @echo off if [%1]==[1] goto :sub1 if [%1]==[2] goto :sub2 set n=a>_2.bat echo %0 2 2.bat echo :loop>_1.bat echo choice /n /cabcdefghijklmnopqrstuvwxyz0 [a-z, 0 for exit]:1.bat for %%i in (*.txt) do call %0 1 %%i echo. echo if not errorlevel 27 goto loop1.bat call _1.bat if exist _1.bat del _1.bat if exist _2.bat del _2.bat goto eof :sub1 set m=%2 _2.bat :sub2 echo2.bat if [%n%]==[a] echo set n=b2.bat if [%n%]==[a] echo if errorlevel 1 if not errorlevel 2 edit %m% 1.bat if [%n%]==[b] echo set n=c2.bat if [%n%]==[b] echo if errorlevel 2 if not errorlevel 3 edit %m% 1.bat if [%n%]==[c] echo set n=d2.bat if [%n%]==[c] echo if errorlevel 3 if not errorlevel 4 edit %m% 1.bat if [%n%]==[d] echo set n=e2.bat if [%n%]==[d] echo if errorlevel 4 if not errorlevel 5 edit %m% 1.bat if [%n%]==[e] echo set n=e2.bat if [%n%]==[e] echo if errorlevel 5 if not errorlevel 6 edit %m% 1.bat if [%n%]==[f] echo set n=e2.bat if [%n%]==[f] echo if errorlevel 6 if not errorlevel 7 edit %m% 1.bat if [%n%]==[g] echo set n=e2.bat if [%n%]==[g] echo if errorlevel 7 if not errorlevel 8 edit %m% 1.bat if [%n%]==[h] echo set n=e2.bat if [%n%]==[h] echo if errorlevel 8 if not errorlevel 9 edit %m% 1.bat if [%n%]==[i] echo set n=e2.bat if [%n%]==[i] echo if errorlevel 9 if not errorlevel 10 edit %m% 1.bat if [%n%]==[j] echo set n=e2.bat if [%n%]==[j] echo if errorlevel 10 if not errorlevel 11 edit %m% 1.bat if [%n%]==[k] echo set n=e2.bat if [%n%]==[k] echo if errorlevel 11 if not errorlevel 12 edit %m% 1.bat if [%n%]==[l] echo set n=e2.bat if [%n%]==[l] echo if errorlevel 12 if not errorlevel 13 edit %m% 1.bat if [%n%]==[m] echo set n=e2.bat if [%n%]==[m] echo if errorlevel 13 if not errorlevel 14 edit %m% 1.bat if [%n%]==[n] echo set n=e2.bat if [%n%]==[n] echo if errorlevel 14 if not errorlevel 15 edit %m% 1.bat if [%n%]==[o] echo set n=e2.bat if [%n%]==[o] echo if errorlevel 15 if not errorlevel 16 edit %m% 1.bat if [%n%]==[p] echo set n=e2.bat if [%n%]==[p] echo if errorlevel 16 if not errorlevel 17 edit %m% 1.bat if [%n%]==[q] echo set n=e2.bat if [%n%]==[q] echo if errorlevel 17 if not errorlevel 18 edit %m% 1.bat if [%n%]==[r] echo set n=e2.bat if [%n%]==[r] echo if errorlevel 18 if not errorlevel 19 edit %m% 1.bat if [%n%]==[s] echo set n=e2.bat if [%n%]==[s] echo if errorlevel 19 if not errorlevel 20 edit %m% 1.bat if [%n%]==[t] echo set n=e2.bat if [%n%]==[t] echo if errorlevel 20 if not errorlevel 21 edit %m% 1.bat if [%n%]==[u] echo set n=e2.bat if [%n%]==[u] echo if errorlevel 21 if not errorlevel 22 edit %m% 1.bat if [%n%]==[v] echo set n=e2.bat if [%n%]==[v] echo if errorlevel 22 if not errorlevel 23 edit %m% 1.bat if [%n%]==[w] echo set n=e2.bat if [%n%]==[w] echo if errorlevel 23 if not errorlevel 24 edit %m% 1.bat if [%n%]==[x] echo set n=e2.bat if [%n%]==[x] echo if errorlevel 24 if not errorlevel 25 edit %m% 1.bat if [%n%]==[y] echo set n=e2.bat if [%n%]==[y] echo if errorlevel 25 if not errorlevel 26 edit %m% 1.bat if [%n%]==[z] echo set n=e2.bat if [%n%]==[z] echo if errorlevel 26 if not errorlevel 27 edit %m% 1.bat echo %0 2 2.bat echo [%n%] %m% :eof |
|
#3
|
|||
|
|||
|
Menu?
Rick wrote:
Those batch file the other guy wrote just emptied themselves. Think the clue was in the If exist then del lines? Which S do you use? The batch doesn't work in W2k/XP (there is mo choice command), but as I said, with this Ss it is trivial. The posted code was tested with Win98 and DS 6. Make a new directory, for example c:\test and save the posted code as txtmenu.bat in this directory. Then create a few text files (text1.txt, text2.txt, text3.txt). CD to this directory and type "dir", you should get: TXTMENU BAT 3.364 02.04.08 9:04 TEXT1 TXT 3 02.04.08 9:04 TEXT2 TXT 3 02.04.08 9:05 TEXT3 TXT 3 02.04.08 9:05 6 Datei(en) 3.373 Byte 401.801.216 Byte frei Now type "txtmenu" and you should get: C:\TESTtextmenu [a] TEXT1.TXT [b] TEXT2.TXT [c] TEXT3.TXT [a-z, 0 for exit]: If you press "b" the file TEXT2.TXT is opened with the editor. If it doesn't work for you, please post a screen shoot of the output. |
|
#4
|
|||
|
|||
|
Menu?
Rick wrote:
> Sorry misunderstood how to use the files. Which S do you use? Now all I get is bad command or file name displayed continously. > Running it with the 'command /y /k gives ' Seems your single step Y is redirected to a file. Just run it normaly, but remove the first line "@echo off", then you should see which command is not found. Also remove the two lines: if exist _1.bat del _1.bat if exist _2.bat del _2.bat What is the content of this two files after you stop the batch? Are you sure there wasn't a copy and paste error of the code (maybe a line wrap). Are there spaces in your file names? Here it works in Win98 and DS6. |
|
#5
|
|||
|
|||
|
Menu?
Rick wrote:
>Which S do you use? Dos 6.21 > Error seems to be on the choice line, it displays :- TESTM>choice /n /c:abc0 [a-c, 0 for exit]: Bad command or file name TESTM>if not errorlevel 27 goto loop Choice is a program,(CHICE.CM) and if that is not found in the path, it fails. It is part of dos6.22, and its help says from dos4.00 up Before that Norton utilitys had something like it. There is also a version in c_snippets. Also google turned up for the below search phrase: choice.com download a lot,reference 2 looks oke. |
|
#6
|
|||
|
|||
|
Menu?
Rick wrote:
> Thanks for a quick reply - but it didn't work. the screen is clear except for the 'choice menu' Use this version: (repace "edit" with the name of your editor) @echo off if [%1]==[1] goto :sub1 if [%1]==[2] goto :sub2 set n=a>_2.bat echo %0 2 2.bat echo :loop>_1.bat echo cls1.bat for %%i in (*.txt) do call %0 1 %%i echo echo1.bat echo choice /n /cabcdefghijklmnopqrstuvwxyz0 [a-z, 0 for exit]:1.bat type _11.bat echo if not errorlevel 27 goto loop1.bat call _1.bat if exist _1 del _1 if exist _1.bat del _1.bat if exist _2.bat del _2.bat goto eof :sub1 set m=%2 _2.bat :sub2 echo2.bat if [%n%]==[a] echo set n=b2.bat if [%n%]==[a] echo if errorlevel 1 if not errorlevel 2 edit %m% 1 if [%n%]==[b] echo set n=c2.bat if [%n%]==[b] echo if errorlevel 2 if not errorlevel 3 edit %m% 1 if [%n%]==[c] echo set n=d2.bat if [%n%]==[c] echo if errorlevel 3 if not errorlevel 4 edit %m% 1 if [%n%]==[d] echo set n=e2.bat if [%n%]==[d] echo if errorlevel 4 if not errorlevel 5 edit %m% 1 if [%n%]==[e] echo set n=e2.bat if [%n%]==[e] echo if errorlevel 5 if not errorlevel 6 edit %m% 1 if [%n%]==[f] echo set n=e2.bat if [%n%]==[f] echo if errorlevel 6 if not errorlevel 7 edit %m% 1 if [%n%]==[g] echo set n=e2.bat if [%n%]==[g] echo if errorlevel 7 if not errorlevel 8 edit %m% 1 if [%n%]==[h] echo set n=e2.bat if [%n%]==[h] echo if errorlevel 8 if not errorlevel 9 edit %m% 1 if [%n%]==[i] echo set n=e2.bat if [%n%]==[i] echo if errorlevel 9 if not errorlevel 10 edit %m% 1 if [%n%]==[j] echo set n=e2.bat if [%n%]==[j] echo if errorlevel 10 if not errorlevel 11 edit %m% 1 if [%n%]==[k] echo set n=e2.bat if [%n%]==[k] echo if errorlevel 11 if not errorlevel 12 edit %m% 1 if [%n%]==[l] echo set n=e2.bat if [%n%]==[l] echo if errorlevel 12 if not errorlevel 13 edit %m% 1 if [%n%]==[m] echo set n=e2.bat if [%n%]==[m] echo if errorlevel 13 if not errorlevel 14 edit %m% 1 if [%n%]==[n] echo set n=e2.bat if [%n%]==[n] echo if errorlevel 14 if not errorlevel 15 edit %m% 1 if [%n%]==[o] echo set n=e2.bat if [%n%]==[o] echo if errorlevel 15 if not errorlevel 16 edit %m% 1 if [%n%]==[p] echo set n=e2.bat if [%n%]==[p] echo if errorlevel 16 if not errorlevel 17 edit %m% 1 if [%n%]==[q] echo set n=e2.bat if [%n%]==[q] echo if errorlevel 17 if not errorlevel 18 edit %m% 1 if [%n%]==[r] echo set n=e2.bat if [%n%]==[r] echo if errorlevel 18 if not errorlevel 19 edit %m% 1 if [%n%]==[s] echo set n=e2.bat if [%n%]==[s] echo if errorlevel 19 if not errorlevel 20 edit %m% 1 if [%n%]==[t] echo set n=e2.bat if [%n%]==[t] echo if errorlevel 20 if not errorlevel 21 edit %m% 1 if [%n%]==[u] echo set n=e2.bat if [%n%]==[u] echo if errorlevel 21 if not errorlevel 22 edit %m% 1 if [%n%]==[v] echo set n=e2.bat if [%n%]==[v] echo if errorlevel 22 if not errorlevel 23 edit %m% 1 if [%n%]==[w] echo set n=e2.bat if [%n%]==[w] echo if errorlevel 23 if not errorlevel 24 edit %m% 1 if [%n%]==[x] echo set n=e2.bat if [%n%]==[x] echo if errorlevel 24 if not errorlevel 25 edit %m% 1 if [%n%]==[y] echo set n=e2.bat if [%n%]==[y] echo if errorlevel 25 if not errorlevel 26 edit %m% 1 if [%n%]==[z] echo set n=e2.bat if [%n%]==[z] echo if errorlevel 26 if not errorlevel 27 edit %m% 1 echo %0 2 2.bat echo echo [%n%] %m%1.bat :eof |
|
#7
|
|||
|
|||
|
Menu?
Rick wrote:
The batch file works ok with up to 4 files. Then every one after the 4th is designated an [e] although pressing e does cause it to open the 5th one. Could it be these lines? > if [%n%] ==[d] echo set n=e2.bat > this is the 1st line where n=e. Every instance after this n=e right up to if [%n%]==[z] then n=e. Sorry, tested it only with three files. Change it to if [%n%] ==[d] echo set n=e2.bat if [%n%] ==[e] echo set n=f2.bat if [%n%] ==[g] echo set n=h2.bat if [%n%] ==[h] echo set n=i2.bat : : |
|
#8
|
|||
|
|||
|
Menu?
Rick wrote:
> Thanks it works ok now, but will the line :- > if [%n%] ==[h] echo set n=i2.bat interfere with the variable used earlier:- This is nothing but an echo command. for %%i in (*.txt) do call %0 1 %%i Rick PS Am i correct in assuming you can get a batch file to display a list of directories and then choose a directory to go into? That isn't worth the effort. Install the Norton Commander (or a free clone). You won't be happy with DS 6 without such a file manager. At least use DSSHELL (it's on the extra floppy of MS-DS 6), but you really should try to get the Norton Commander. |
![]() |
| Viewing: Web Development Archives > FAQs > MS DOS > Menu? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|