I have a basic bit of code which I am using to delete text files within a given directory:
For Each file As IO.FileInfo In New IO.DirectoryInfo(filePath).GetFiles("*.txt")
If (Now - file.CreationTime).Days > intdays Then file.Delete()
Next
filePath
is the directory where the files reside.
intdays
is a variable which determines how many days the files should be retained for.
To test the code i set intdays to 0, assuming that it would delete any files in the directoy. However it doesn't, but creates no errors.
The time "Now" is #2/8/2012 13:59:00 PM# which is greater than 0. But I'm confused as to why it doesn't then delete the file?
The difference between the dates is less than a day.
You are calling the Days
property, which is an integer type - this will be 0
for intervals that are less than a day long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With