开发者

Batch script - invalid syntax in FOR /F

I have a batch script which is supposed to parse a file with file names and timestamps in it.开发者_运维问答

:MAIN

SETLOCAL EnableDelayedExpansion

FOR /F "tokens=1,2,4 skip=7" %%A in (C:\list_of_psa_files.txt) DO
@echo %%A %%B %%C 

exit

The file C:\list_of_psa_files.txt has the following data in it

Volume in drive C is Windows XP 6.6
Volume Serial Number is AC12-84AA

Directory of C:\Test

10/05/2011 03:17 PM <DIR> .
10/05/2011 03:17 PM <DIR> ..
10/05/2011 01:21 PM 4,393 1-16332-1008261.psa
10/05/2011 01:21 PM 4,863 1-16332-1011698.psa
10/05/2011 01:21 PM 4,793 1-16332-1023151.psa
10/05/2011 01:21 PM 4,916 1-16332-1035695.psa
10/05/2011 01:21 PM 4,524 1-16332-1037029.psa
10/05/2011 01:21 PM 4,235 1-16332-1049340.psa
10/05/2011 01:21 PM 3,135 1-16332-1049926.psa
10/05/2011 01:21 PM 4,657 1-16332-1054756.psa

However, when I am running my script it is failing with a message invalid syntax. Can somebody please help me figure out where am I going wrong.

All I am trying to do is to get the date, time and the filename without the extension written to a new file from my old file.

Thanks for your time - appreciate it.

Sanders.


If you really have your echo on a separate line (and it's not an artefact of the editing process), you can't do that. You will need to use either one line or:

FOR /F "tokens=1,2,4 skip=7" %%A in (C:\list_of_psa_files.txt) DO (
    @echo %%A %%B %%C 
)

When I create the file and script you show, I get:

The syntax of the command is incorrect.

When I then change it to my suggested variant, it outputs:

10/05/2011 01:21 4,393
10/05/2011 01:21 4,863
10/05/2011 01:21 4,793
10/05/2011 01:21 4,916
10/05/2011 01:21 4,524
10/05/2011 01:21 4,235
10/05/2011 01:21 3,135
10/05/2011 01:21 4,657

as expected. The same output appears when you do it on one line with:

FOR /F "tokens=1,2,4 skip=7" %%A in (C:\list_of_psa_files.txt) DO @echo %%A %%B %%C 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜