-2

I want to delete .txt extention files in my computer every 30 days using batch script...

files name are like:

filename_20082013.txt
filename_21082013.txt
filename_22082013.txt
filename_23082013.txt
tshepang
  • 12,111
  • 21
  • 91
  • 136
Adam Bremen
  • 685
  • 1
  • 7
  • 18
  • Ok, and what have you done so far? Can we see the script you're working on? –  Aug 26 '13 at 17:37

3 Answers3

2

suggestion for approx. 30 days, run the command on the first day of the month:

del *072013.txt

for this month and

del *082013.txt

for the next month.
The command also works in a batch script.

Endoro
  • 37,015
  • 8
  • 50
  • 63
2

For Windows:

forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"

So:

forfiles -p "C:\your\path" -s -m *.txt -d -30 -c "cmd /c del @path"

Source: Batch file to delete files older than N days

This will delete files that are at least 30 days old (you can change it to any number)...now you need to schedule this task to run every 30 days:

You can use Windows Task Scheduler:

You can use Windows Task Scheduler

http://windows.microsoft.com/en-us/windows7/schedule-a-task

Or you can use StreamServe Task Scheduler:

Or you can use StreamServe Task Scheduler

http://streamshare.streamserve.com/Articles/Article/?articleId=424

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

You are looking for the "Task Scheduler" on Windows, or a cron job on Unix.

Adam Burry
  • 1,904
  • 13
  • 20