Page 1 of 1

For \F not working --- Revert immediately please

Posted: 06 Oct 2014 22:04
by pratik151192
Hi,

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.

Re: For \F not working --- Revert immediately please

Posted: 06 Oct 2014 22:34
by foxidrive
Your double quotes aren't real double quotes, for one.

Re: For \F not working --- Revert immediately please

Posted: 06 Oct 2014 22:38
by pratik151192
yes, I have reviewed that. I do not know why when I post it here, it appears slanting

Re: For \F not working --- Revert immediately please

Posted: 06 Oct 2014 23:00
by foxidrive
pratik151192 wrote:yes, I have reviewed that. I do not know why when I post it here, it appears slanting


If you copy and pasted the code then you probably aren't familiar with ascii codes and hex viewers.

Load the code into a text editor in MSDOS mode and examine them.

Re: For \F not working --- Revert immediately please

Posted: 07 Oct 2014 01:32
by ShadowThief
Copying your slanted quotes reproduces your error. You MUST be using the double quotes that appear when you press SHIFT and the ' button that is next to enter.

Re: For \F not working --- Revert immediately please

Posted: 07 Oct 2014 12:13
by Endoro
ShadowThief wrote:when you press SHIFT and the ' button that is next to enter.

It depends on your local keybord. It appears here when I press SHIFT and 2 :D

Re: For \F not working --- Revert immediately please

Posted: 07 Oct 2014 12:16
by Compo
…also is this not more like what you wanted?

Code: Select all

@Echo Off
If Not [%1]==[] GoTo RUN
Echo You must supply a file name as an argument.
GoTo DONE

:RUN
(Set fname=)
For /F "Tokens=10,11 Delims=/. " %%A In ('Find "txt"^<%1') Do (
   Set fname=%%A %%B)
If Not Defined fname GoTo DONE
Echo %%fname%%=%fname%
>scriptt.bat (Echo Set fn=%%1
   Echo Set extn=%%2
   Echo Echo %%%%fn%%%% %%%%extn%%%%=%%fn%% %%extn%%)
Call scriptt.bat %fname%
Del scriptt.bat

:DONE
Pause
…minus the commented lines

Re: For \F not working --- Revert immediately please

Posted: 08 Oct 2014 02:09
by pratik151192
Thanks for the solutions and suggestions. This problem got solved