Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DELETE FILES BY DATE

Status
Not open for further replies.

Volkmaniac

Technical User
Mar 19, 2003
104
US
This is a script I took off of Is there anyway I can alter this to delete the latest files by date as opposed to just deleting the newest? I tried changing $FLTIME to $FDATE but that didn't work. I need to delete all the newest files to a directory from the most current date.

proc main
long lDate = 0 ;Hold long value representing date/time of file
string sFname ;Contains full filespec of currently-latest file

if findfirst "S:\Client Services\LETTERS\*.*" "NRHSA" ;Search all files in specified directory
sFname = $FILESPEC ;Set latest file to that of initial file
lDate = $FLTIME ;Set time/date to that of initial file
while findnext ;Continue searching hile more files remain
if $FLTIME <= lDate ;If next file is older than current latest file
lDate = $FLTIME ;Set time/date to that of older-found file
delfile sFname ;Delete previously-latest file
sFname = $FILESPEC ;Set latest file variable to the older-found file
else ;If file was not older...
delfile $FILESPEC ;Then delete newly-found file
endif
endwhile
else ;No files found in specified directory
usermsg &quot;No files found!&quot;
endif
endproc
 
I'd only need to delete the newest files. This directory is going to have two files downloaded to it everyday. Since they'd both have the same date I'd like to delete the most recent files that share the same date. If you know how to do the latter (range of dates) I'm sure I'll need to use that sooner or later. I tried editing the script above and I ended up deleting a bunch of my scripts.
 
Are the files that are being downloaded to that directory always the same name? Are there any files in the directory other than the two files that are downloaded to that directory? If the answer to the first question is no and the second yes, can there be more than two files with the same date, but different sets of timestamps? I'm trying to get a handle on just what the script is needing to delete and what it should not.


aspect@aspectscripting.com
 
No, they're not the same name. They're assigned a batch number as a filename and downloaded to a Unix box. They will be the only files in that directory. They're then ftp'd to that directory (local), zipped (I'm using the zip script) and then ftp'd to another site. They're not the only files in the local drive but they're the only files that aren't zipped. I don't always know what the filename will be because multiple people will run batches throughout the day. I read one of your previous threads where you said that ProComm can't read any of the file or system variables. What I'd like to do is delete the files in the Unix directory after they're copied (ftp'd) to local, and then I'd like to delete the same files again on local after they're zipped.
 
OK, let's break this into two separate problems. First, the files on the Unix system. After you have FTP'd the files locally, will you want to delete all files in the current directory on the Unix system (sounds that way to me)? Since we are transferring the files via FTP, we can get the filelist for that directory and find the filenames that are present. This would then let us use a delfile command to delete local copies of those files after they have been zipped up.

I have a script at that shows how to make a connection to an FTP server and retrieve the file list, among other tasks. When the file list is opened (line 40), that file will contain all the files in the current directory on the FTP server. You would want to delete lines 43-46, and replace them with code to retrieve the file and save that filename to another variable that you read later to delete the downloaded file after it has been added to the ZIP file.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top