1

I have a directory that is set up as \server\\year\month\day\x, .../y and .../z. I need a batch file that will delete videos located in the x folder in each user's directory for each month day and year based on a retention period (IE 60 days). Then delete the files in Y based on a different period (IE 730 days)

I have forfiles -p "\\server\username\year\month\day\x" -s -m *.* -d -60 -c "cmd /c del @path" but I am not sure how to do the loop in the path to search all of the sub directories from the network folder to find only the X folders.

Is there a way to do this without using the created on date attribute, just in case the camera's date/time was incorrect when the video was taken. Thanks in advance for the help! (If anyone knows a syntax that I could research I would greatly appreciate it)

Justin
  • 23

1 Answers1

0

forfiles doesn't accept UNC paths AFAIK, you need to associate that network address to a drive letter ("S:" as Server, for instance)

net use S: \\server\username\year\month\day\ /PERSISTENT:YES

Then test your first command, by using echo instead of del as @JosefZ suggested on his comment:

forfiles -p S:\x -s -d -60 -c "cmd /c if @isdir==FALSE echo @path"

You don't need the generic mask *.*, that's implicit. Use the -m switch just to filter specific file classes (ex. *.mp4).

Once you're happy with the results, go for it:

forfiles -p S:\x -s -d -60 -c "cmd /c if @isdir==FALSE del /f @path"

forfiles -p S:\y -s -d -730 -c "cmd /c if @isdir==FALSE del /f @path"
SΛLVΘ
  • 1,405
  • This works great for the one day and I can make it work with:`net use z: "\server...\day" /PERSISTENT:NO

    forfiles -p "z:\x" -s -d -60 -c "cmd /c if @isdir==FALSE del @path" forfiles -p "z:\y" -s -d -730 -c "cmd /c if @isdir==FALSE del @path" net use z: /DELETE /YES` then move on to the next day and do it again but I am concerned that running this for all 365 days for each user will cause some performance issues.

    – Justin Oct 24 '15 at 21:07
  • I broke it down to check each month with `for /f "tokens=*" %%G in ('dir /b /s /a:D "\server\username\2015\12 December??"') do (net use z: "%%G"

    /PERSISTENT:NO forfiles -p "z:\x" -s -d -60 -c "cmd /c if @isdir==FALSE echo @path" net use z: /DELETE /YES)`

    – Justin Oct 25 '15 at 00:41
  • @Justin, I cannot reproduce in detail what you are trying to do, as you did not give enough... details. Just a couple of hints: check pushd /? and popd /?, I think they work better for what you are trying to achieve; multiple commands on a line need to be separated by &. – SΛLVΘ Oct 25 '15 at 10:42