I want to delete all files in a given folder that are older than 3 days from today's date. I tried using a 'Foreach Loop container' with a 'File System' task inside it but found I couldn't access any file properties such as the file creation date. Am I using the wrong task for this job? TIA, Barkingdog P.S. I just need it to delete files older than 7 days. Deleting old files through SSIS?! Glenn Tucker. I have a folder in d drive called Archive (d: archive) which stores all data load files. The name of these files various, and I need to create a ssis job to delete all these archived load files older than 7 day. History of the problem: I used the sql 2005 Database maintenance program to setup our database backup jobs. One day I noticed that the free space on the drive where we keep the dumps had grown small. I found that we had at least 4 weeks of dumps in there, not the 3 days I wanted to keep! I looked but could not find the 'delete file' option in the SSIS package generated by the Database Maintenance Wizard. No wonder the files were piling up. Hi, I'm not sure if you found out the answer to your question, nor if this is what you are looking for, however, when creating a maintanance plan, you can use a 'Maintenance Cleanup Task' to delete files which are older than X days old. The trick to this is to make sure you've ticked the correct boxes. For instance, I setup my backups to backup to G: SQLBackups and tick the 'Create A Subdirectory for each database' option. Therefore, when I put in a corresponding 'Maintenance Cleanup Task', I make sure that I enter G: SQLBackups in the 'Folder' box, but also tick the 'INCLUDE First Level Subfolders' option. (This caught me out once as I couldnt understand why, even with the task in place, it wasnt deleting.) This definately works for SQL backups, and also SQL transaction logs (just change the file extension to trn, not bak) I'm not sure if you want to delete different files that aren't SQL backups but it MIGHT be possible to simply enter a different file extension in there to delete other types of files. Regards Andy. 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 $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. 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). Email Id removed for security said: > We generate about 1000 reports per hour on our webserver and > run a nightly script to remove these files. Unfortunately, that is not often enough > and need to have a script that we can run every hour > that removes old files (older than say 1 hr). > Can someone steer me to a solution that uses the system time, > and removes files from our 'reports' directory that are older? Thx in Advance This script will do exactly what you need. I will assume that these report files are in folder 'C:/hourly reports'. I am adding comments so you can follow the logic. # Script HourlyDelete.txt # Go to reports folder. Cd 'C:/hourly reports' # Collect a list of files that were CREATED more than an hour ago. Var str list, file lf -r -n '*' '.' ( $fctime $list # Delete each file in $list one by one. While ($list ') do lex '1' $list > $file echo -e 'DEBUG: Deleting file ' $file system del (' '+$file+' ') done Script is in biterscripting.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2018
Categories |