I'm trying to make a batch file to run from the Task Scheduler that will clean up some residual files left from a programme that converts video.

At the moment I have:

:: begin the script --> start in UNC path
PushD "\\UNC\ShareDrive\" &&(

    :: clear the log file every 30 days
    Forfiles -m *.log -d -30 -c "cmd /c BREAK>mbWatchfoldersCleanup.log"

    :: delete *wav, *.mov, *.mp4 files older
    :: than 7 days and add to the log file
    for %G in (.wav, .mov, .mp4) do
        Forfiles -s -m *%G -d -7 -c "cmd /c del /Q /S @path >> mbWatchfoldersCleanup.log"

) & PopD

My intention is to have the Forfiles to run from the UNC path.

But I also would like it to match and search specific folders (haven't figured out how to do that).

What occurs in the video conversion is, once the MOV and the WAV file have been muxed, it deletes the MOV file, and moves the WAV into a __completed folder. If the file fails to mux, both MOV and WAV are moved into __failed.

I'd like the cmd /c del /Q /S @path to search only folders matching the __completed and the __failed then delete any matching filetypes.

I am running into issues where the folders appear multiple times within the share:

-- username01

-- username02

-- username03

Is this something possible to be altered and have it delete only within the selected folders? Or is it something that should be run on two scripts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.