Scheduled Windows Task to delete files on Server

Try this one, its more thorough it comes from this list a few months back. Just schedule it and it should work fine. Change the "Path" ofcourse.
:: Will scan the directory and delete any file older than XX days :: The xx being whatever value comes after the -d flag

:: Clear General EpicorData files generated by the server
forfiles -p "C:\Epicortemp" -d -15 -m Assign* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -1 -m baq* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m bfc* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m bpm* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m BusEntity* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m COAL* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -7 -m DBI* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m GLBCOA* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m GLJrn* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -7 -m lbi* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -5 -m rcd* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m RestrictFcts* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m srt* -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp" -d -15 -m trp* -c "Cmd /c del Echo @Path"

:: Clear User Specific files that linger by user
forfiles -p "C:\Epicortemp\Reports" /s -d -90 -m *.xml -c "Cmd /c del Echo @Path"
forfiles -p "C:\Epicortemp\Reports" /s -d -90 -m *.txt -c "Cmd /c del Echo @Path"

:: Clear User Specific bat files that linger by user
forfiles -p "C:\Epicortemp\Reports" /s -d -15 -m *.bat -c "Cmd /c del Echo @Path"

forfiles -p "C:\EpicorData" -d -15 -m Assign* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -1 -m baq* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m bfc* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m bpm* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m BusEntity* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m COAL* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -7 -m DBI* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m GLBCOA* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m GLJrn* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -7 -m lbi* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -5 -m rcd* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m RestrictFcts* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m srt* -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData" -d -15 -m trp* -c "Cmd /c del Echo @Path"

:: Clear User Specific files that linger by user
forfiles -p "C:\EpicorData\Reports" /s -d -90 -m *.xml -c "Cmd /c del Echo @Path"
forfiles -p "C:\EpicorData\Reports" /s -d -90 -m *.txt -c "Cmd /c del Echo @Path"

:: Clear User Specific bat files that linger by user
forfiles -p "C:\EpicorData\Reports" /s -d -15 -m *.bat -c "Cmd /c del Echo @Path"



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile

Quis custodiet
ipsos custodes?


On Fri, Jun 19, 2015 at 3:16 PM, Miguel Santillan msantillan@… [vantage] <vantage@yahoogroups.com> wrote:

Â
<div>
  
  
  <p>

I have this in a bat file, the file is triggered through windows task scheduler.

I have the credentials saved.

Â

It seems to work when I type each line in the command prompt. If I click on the batch file it opens and closed immediately.

Â

forfiles /p "D:\EpicorData\Reports\MANAGER" /s /d -2 /m *.xml /c "Cmd /c del Echo @Path"

forfiles /p "D:\EpicorData\Reports\MANAGER" /s /d -2 /m *.txt /c "Cmd /c del Echo @Path"

forfiles /p "E:\EPICORTEMP" /s /d -1 /m *.* /c "Cmd /c del Echo @Path"

Â

Miguel A. Santillan

ERP Analyst

Compass Manufacturing Systems

Â

</div>
 


<div style="color:#fff;min-height:0;"></div>

I have this in a bat file, the file is triggered through windows task scheduler.

I have the credentials saved.

 

It seems to work when I type each line in the command prompt.  If I click on the batch file it opens and closed immediately.

 

forfiles /p "D:\EpicorData\Reports\MANAGER" /s /d -2 /m *.xml /c "Cmd /c del Echo @Path"

forfiles /p "D:\EpicorData\Reports\MANAGER" /s /d -2 /m *.txt /c "Cmd /c del Echo @Path"

forfiles /p "E:\EPICORTEMP" /s /d -1 /m *.* /c "Cmd /c del Echo @Path"

 

Miguel A. Santillan

ERP Analyst

Compass Manufacturing Systems