I have a bat file in which I am extracting the name of all the .txt files from another file. This operation was previously done using debug commands,etc. but for Windows NT I am using for loops with switch commands.
Code: Select all
:: @echo off
:: This batch file sets the file created date into
:: the environment under Win9x. This kind of thing
:: is often needed by scripts trying to determine
:: whether or not to update a file.
:: It uses the DEBUG command to extract the created
:: date from the output of the DIR command. The output
:: of the Win9x DIR command is like this:
:: TEST BAT 582 04-23-00 11:02p test.bat
:: Notice the date starts on the 29th character (hex 1D)
:: so we replace the first 28 characters (hex 1C) with
:: spaces (hex 20) with this line - "f 100 l 1c 20"
:: Then enter the string "set created=" just before
:: the date at the 16th character (hex 10) so that
:: 16 (our start point) added to the lenghth of
:: "set created=" (12 characters) ends us at the 28th
:: character. Notice also the created date ends at
:: character 36 (hex 24), so we trim things at that
:: point (just after the "rcx" line by setting the
:: file length to 24 hex. After that, just we just
:: Write the file to disk ("w") and quit ("q").
:: If you have NT, you should learn how to use the
:: switches in the FOR command so you can avoid this!
:: The use of DEBUG to extract data from lines is only
:: needed under Win9x.
if [%1]==[] goto HELP
goto RUN
:HELP
cls
echo You must supply a file name as an argument.
goto DONE
:RUN
set fname=
for /F “tokens=1-11,* delims=/. “ %%A in (‘type %1^| find “txt”‘) do set “fname=%%J %%K”
echo %fname%
:: pause
> scriptt.bat echo set fn=%%1
>> scriptt.bat echo set extn=%%2
>> scriptt.bat echo %fn% %extn%
call scriptt.bat %fname%
del scriptt.bat
:DONE
I get the following error when this script runs:
1-11 was unexpected at this time. Process Exit Code 255. The step failed.
Please help.