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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check date created on a file 2

Status
Not open for further replies.

SQLWilts

Programmer
Feb 12, 2001
651
0
0
GB
I want to periodically purge a folder of all files, but I want to keep the last 7 days worth. Problem is, I can't seem to find out how to check/compare the date created/last modified date for the file - any ideas? The files are process control files from a paper machine and have no extension.
 
somthing like
---------------------------------
Const Mypath = "d:\tmp\"
Dim CurFile As String
CurFile = Dir(Mypath & "*.*")
While CurFile <> &quot;&quot;
If DateDiff(&quot;d&quot;, FileDateTime(Mypath & CurFile), Date) > 7 Then Kill Mypath & CurFile
Wend
---------------------------------
should do the trick
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
sunaj,

Thanks for the tip, but when I run this, I get a &quot;file not found&quot; error - sorry, very inexperienced here
 
Did you change the path?
p.s. be carefull with this code - it will delete files, for good, on your harddisk! Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Sunaj,
Yep, changed path - it deletes one file and then comes up with the file not found error - a little mystified to be honest with you!
 
I think you are missing another call to the DIR function just before the WEND statement
 
WarriorPrincess is absolutely right, the code should read
---------------------------------
Const Mypath = &quot;d:\tmp\&quot;
Dim CurFile As String
CurFile = Dir(Mypath & &quot;*.*&quot;)
While CurFile <> &quot;&quot;
If DateDiff(&quot;d&quot;, FileDateTime(Mypath & CurFile), Date) > 7 Then Kill Mypath & CurFile
CurFile = Dir
Wend
--------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Thanks to both of you - works like a dream - have a star each cos you got me out of a corner :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top