Task Scheduler - Batch File not running properly

Soldato
Joined
12 Jan 2006
Posts
4,597
Location
Edinburgh
I've got some batch files set up to automatically rename some files - basically just append the date to the start of the file name.

The batch file is located in the same directory as the files being renamed and everything seems to work fine when the batch file is run manually.

Batch File contents :

Code:
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "FileA.bak" %%f-%%e-%%d_FileA.bak
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "FileB.bak" %%f-%%e-%%d_FileB.bak
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "FileC.bak" %%f-%%e-%%d_FileC.bak

If I then set up a Scheduled Task to run the batch file, then it seems to fail every time. The files just aren't renamed.

I have got another very similar batch file in a different directory which just deals with one file (eg FileA) and this seems to work fine, but for some reason this one (with multiple files) fails.

I guess I could split things out into individual batch files if I had to and see if that works, but I thought I'd see if anyone had any suggestions as to what might be going wrong.

Any ideas?
 
Can you shove absolute paths in to see if it works, I'm assuming it works if you run it manually from a random folder?

I'd almost always put it down to the task scheduler settings as above otherwise.
 
Have you configured the 'start in' field?

Thanks for the various replies - turns out that this was all it was.

For the task which worked, the start in field was set to the same folder as the batch file was located.

For the task which didn't work, there was no start in field set. Have changed that now and it all seems to work fine.

Solved :)
 
Back
Top Bottom