Search : in
By :

Batch script to delete file older than 30 day

Last answer on Sep 28, 2009 1:40:48 pm BST sd6340, on Feb 27, 2009 7:32:51 pm GMT 
 Report this message to moderators

Hello,

i would like to create the batch script which could copy the 30 days older files from one folder to another. And also deletes the 30 days old files from the source folder after copying to the destination folder.


Any help would be appreciated!

Best answers for « batch script to delete file older than 30 day » in :
Batch Script - Move files to \%date%\%time%\ Show Batch Script - Move files to \%date%\%time%\ Issue Solution Note Issue I have been trying to make a simple batch script to create database backups and move then into a folder named by date, and a sub folder by time. This is what I...
Writing in batch in text file ShowWriting in batch in text file To write in a file text, you just have to use a redirect: echo text > output_file.txt To write in an existing file: echo " Write at the end of the file ">> output_file.txt
How to restore deleted files ShowHow to restore deleted files Download a recovery tool There are easy and effective recovery tools available for download on the web and some have the major advantage of being free. Zero Assumption Recovery Download Link: http://www.z-a...
Permanently delete files from trash bin ShowPermanently delete files from trash Sometimes when emptying the trash some files stays and refused to be deleted! You just have to use a command: Start the Terminal - Type "sudo rm • • •-R" - Drag files, folders that you want...
Download Recover Deleted Fat File 2 ShowRecover Deleted Fat File is a recovery tool for hard disks. It allows to restore damaged, corrupt, formatted, overwritten, deleted files. The application supports the following file systems: FAT12, FAT16, FAT32, SATA, ATA, SCSI and the following...
Operating Systems - MS-DOS - Tips ShowSetting the CD-ROM drive The CD-ROM drive is configured in the config.sys and autoexec.bat system files. The CD-ROM drive device driver must be configured in the config.sys file (even if the device is automatically detected in Windows). To do...

1

Marrina, on May 26, 2009 11:33:47 pm BST
  • +1

Please share the answer of this script with me, thanks.

Reply to Marrina

2

nobody, on May 31, 2009 12:32:12 am BST
  • +4

Deletion:

find ./ -type f -mtime +30 -exec rm -- {} \;

Copy:

rsync -avxSH <source> <destination>

Reply to nobody

6

D.eco, on Sep 25, 2009 5:48:32 pm BST

Please, Exercise caution with the above command!!!

Finding all the old files starting up from your root folder and excluding the old files Is really NOT a good idea!!!

Substitute ./ with the path of your choice and be smart enough not to put a system or config folder in the way of this command.

Reply to D.eco

3

unreal, on Jul 10, 2009 8:47:56 am BST

He was asking for a "batch" script (on windows , .bat) , and not a *nix "bash" script :)
i'm looking for the same thing as well :)

Reply to unreal

4

SenHu, on Jul 13, 2009 3:07:05 pm BST
  • +3

The following windows script will move files older than a given date from C:\folder1 to C:\folder2. By older, I am assuming that they are not modified after a certain date. The date is passed in the format yyyymmdd . When files are moved to folder2, they are automatically deleted from folder1.

# Script movefiles.txt
# Input argument - date
var str date

# Get a list of files not modified since $date.
var str list ; lf -n "*" "C:\folder1" ( ($ftype == "f") AND ($fmtime < $date) ) > $list
# Move files one by one.
while ($list <> "")
do
    var str file ; lex "1" $list > $file
    system move $file "C:\folder2"
done


The script is in biterscripting. Download biterscripting from http://www.biterscripting.com . Save the script as C:\Scripts\movefiles.txt. Start biterscripting. Call the script as

script movefiles.txt date("20090613")


The above will move files that have not been modified since June 13, 2009 (30 days before today).

Sen

Reply to SenHu

5

punx, on Sep 24, 2009 4:42:08 am BST

Is there a way to delete all PDF files in a certain directory?

Reply to punx

7

 SenHu, on Sep 28, 2009 1:40:48 pm BST

To delete all PDF files in a certain directory (say C:/Directory1), use this script.

# Script DeletePDF.txt
var str list ; lf -n "*.PDF" "C:/Directory1" > $list
while ($list <> "")
do
    var str file ; lex "1" $list > $file
    system -r del /FQ $file
done


Save the script as C:/Scripts/DeletePDF.txt, start biterscripting ( http://www.biterscripting.com ), enter the following command

script "C:/Scripts/DeletePDF.txt"

Reply to SenHu