code runs in cmd window but not as .bat

August 31, 2009 at 14:05:55
Specs: Windows XP
Hi all,

I'm working on .bat files to run properly on a WinXP os. I can get the following lines of code to work properly in the command window, but when contained in a three line ".bat" file, the command window opens for a split second and closes and nothing else happens.

@echo off
cd C:\dir1\dir2\
for /f "tokens=*" %X in (file.txt) do (cd %X & cksum * >> C:\dir1\dir2\output.txt)

"file.txt" contains a number of directory structures:

...and so on

So I am essentially trying to make directory structures variable and then perform a "cksum" function on the files in that directory.

Any suggestions/advice would be most appreciated.

See More: code runs in cmd window but not as .bat

Report •

August 31, 2009 at 14:20:27
Replace %X with %%X as inside batch files the For variables must be prefixed by a pair of %% while just one is required when the statement is typed at prompt.

Report •

August 31, 2009 at 14:36:56
Thanks a IVO, that did the trick ! I'm sure I'll be posting more questions as time goes along.


Report •

Related Solutions

Ask Question