File/Folder Purging - Best practice?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Posts: 507
Joined: 07 Jan 2016 07:47

File/Folder Purging - Best practice?

#1 Post by SIMMS7400 » 14 Sep 2020 04:18

Hi Folks -

I'm trying to developing a purging process but I haven't been able to land on anything that I really like yet so wanted to get your opinion. What is the best way to go about this?

Can I merely just use a forfiles to remove an entire directory based on AGE, or should I remove files first and then the folder/subfolders?

I have this piece of code:

Code: Select all

FORFILES /P "D:\Data\Imports" /S /M "*" /D -14 /C "CMD /C if @ISDIR==TRUE echo RD /S /Q @PATH"
In my \Import directory, I have sub-folders named as YYYY_MMDD to hold my imports that I load into my target application. Therefore, wondering the best, most effcieint way to purge a setup like this?

I understand my above code will not purge empty dirs, so in the case, I planned to just use a ROBOCOPY to take care of that.

Code: Select all

ROBOCOPY "D:\Data\Imports" "D:\Data\Imports" /S /MOVE
What are your thoughts?

Post Reply