1.

Solve : Old files deletion?

Answer»

Hi all,

   Im looking for a batch script which will delete older than 7 days file. i have script which will copy some files into the FOLDER in .yyyddmm format.

   Everyday folder size will grow - To avoid FREE space issue, need a script which will KEEP last 7 days files and the older files need to be deleted permanently.

Please help me on this

Regards
Paulwintech

Copy and paste the batch file given in the first POST of the link and save it.

http://www.computing.net/answers/programming/delete-files-older-then-xdays/15229.html

Now you can read this part of the batch file for help:

Code: [Select]:SYNTAX
Echo.
Echo USAGE:
Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo Where:
Echo [Days] = Number
Echo Determines the number of days previous to Today that will be selected.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG" Deletes all LOG files older than 5 days.
Echo.
Echo [Dir] = Path
Echo "Delete-Files.bat 120 C:\Temp *.LOG" Deletes all LOG files from the
Echo "C:\Temp" directory that are older than 120 days.
Echo.
Echo [File-Extension] = wildcards and extension
Echo This detemined which files or file-types that will be deleted.
Echo.
Echo Wildcards are allowed. [* ?]
Echo Examples: [*.* , *.LOG , ~*.*]
Echo.
Echo Example: "Delete-Files.bat 15 C:\Temp *.LOG"
Echo Example: This will delete all LOG files older than 15 days from C:\Temp
Echo.
Echo [Sub-Directory Search] = 1 or 0
Echo.
Echo Possible values {0 , 1}
Echo A value of "0" or blank, will not search sub-directory for possible files
Echo to delete.
Echo.
Echo A value of "1" and only "1", will search every directory underneath the
Echo the specified directory. If C:\Temp and "1" then C:\Temp and C:\Temp\srbackup\..
Echo will be searched and evaluated for file deletion.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG 1"
Echo This will search C:\Temp and ALL sub-directories for *.LOG files, older
Echo then 5 days and delete them.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG"
Echo This will search ONLY C:\Temp for *.LOG files older than 5 days and
Echo delete those that qualify.
Echo.
Echo [Read_Only_Delete] = 1 or 0
Echo WARNING!
Echo The Sub-Directory Search value must be present for this to work.
Echo.
Echo This fifth control-switch will force the deletion of Read-Only files.
Echo Enter a "1" if the forced deletion of Read-Only files is wanted.
Echo Leave the value empty or specify "0" to keep Read-Only untouched.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and will
Echo be deleted even if Read-Only. This switch will delete regular and Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 0"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and
Echo will NOT delete Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 1 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, in all subdirectories of C:\Temp
Echo and will delete files Read-Only and regular.
Echo.
--------------------
Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo -- End of help --



Discussion

No Comment Found