1

I have created a batch file with the following line:

forfiles /p L:\percepsrvr\SQL /s /m *.bak /d -4 /c "cmd /c del /q @PATH "

This deletes any files older than 3 days and works when I run the batch file.

However, when I try to run this batch file as part of a scheduled task the line of code fails to execute. I think it might be because of the mapped network drive (L:) but don't know for sure.

I have the scheduled task running as myself to make sure it has the same permissions as when I run it manually. The scheduled task is running on a Win2008r2 server box and L:\ is on a Win2003 SP2 server box.

Anyone know what might be keeping this from working properly or how to debug a scheduled task?

TIA Brian

BrianKE
  • 4,035
  • 13
  • 65
  • 115
  • Have you tried running this without using the map - using \\Servername\ShareFolder\ ? – Arun Oct 11 '11 at 17:16
  • UNC paths are not supported in forfiles. – BrianKE Oct 11 '11 at 17:36
  • Didn't know that. Thank you! You might want to try the solution in this post: http://stackoverflow.com/questions/7503491/forfiles-with-unc-path – Arun Oct 11 '11 at 17:46

1 Answers1

1

In case anyone comes across this post I found a solution as follows:

ROBOCOPY "D:\Backup Data\percepsrvr\SQL" "\\belgrade\v$\percepsrvr\SQL"

ROBOCOPY "\\belgrade\v$\percepsrvr\SQL" "\\belgrade\v$\percepsrvr\SQL\Old" *.* /move /minage:10
DEL "\\belgrade\v$\percepsrvr\SQL\Old\*.*" /Q

Basically, move the files to delete to another directory and then delete that directory (which can be done with RoboCopy).

BrianKE
  • 4,035
  • 13
  • 65
  • 115