|
Answer» The batch file below receives a file which is type at DOS prompt, e.g., example.bat . What I would like to do is to print out an error message on the screen e.g., MUST ENTER NAME OF FILE. Then I would send the user back to the beginning if the user FORGETS to enter file name.
dir ..\test\%1.cob dir ..\copy\%1.cob choice /c:yn continue if errorlevel = 2 goto :finish if errorlevel = 1 goto :continue :continue echo on copy \test\%1.cob \copy\test /y :finish
Tnks in anticipationWhen is this due to be handed in ?
It sounds like homework to me .... if not, this page has your answer http://www.csulb.edu/~murdock/if.html
GrahamIf the batch file requires a file name as a parameter, and the user doesn't specify the parameter, then the only way have them go back and provide the parameter is to have them re-run the batch file. Depending on the command processor, you COULD prompt for the parameter, also.
I think you want something like this:
Code: [Select]echo off if not {%1}=={} goto arg1OK echo MUST ENTER NAME OF FILE goto :finish :arg1OK dir ..\test\%1.cob dir ..\copy\%1.cob choice /c:yn continue if errorlevel = 2 goto :finish if errorlevel = 1 goto :continue :continue echo on copy \test\%1.cob \copy\test /y :finish Or to prompt (in command prompt under Windows 2000 / XP / 2003):
Code: [Select]echo off if {%1}=={} (SET /p FILENAME=Please enter name of file: ) else set filename=%1 dir ..\test\%filename%.cob dir ..\copy\%filename%.cob choice /c:yn continue if errorlevel = 2 goto :finish if errorlevel = 1 goto :continue :continue echo on copy \test\%filename%.cob \copy\test /y :finish Thank you... I used your first example and it worked.
|