Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27417

Problem with File.delete

$
0
0
I am trying to write a simple Cacheing function. I am checking to see if a file saved on the hard drive is order than some prescribed limit. If it is less than the limit, I used the cached file, if older I download and save a new file. I have run into problems checking the age of the file. here is some test code
Code:

 
        Dim filesavetime As Date
        Dim filesavetime2 As Date
        Dim sw As StreamWriter

        filesavetime = File.GetCreationTime("myfile.txt")    ' this file was created minutes earlier
        File.Delete("myfile.txt")  ' this should not be needed.
        sw = File.CreateText("myfile.txt")
        sw.WriteLine("dog")
        sw.Close()
        filesavetime2 = File.GetCreationTime("myfile.txt")

The result is the filesavetime is exactly the same as filesavetime2. I know the file.delete should not be needed. The file.createText should overwrite the file. I just tried to use it to clear out the file.

Any idea on how to accurately get the file creation time?

Viewing all articles
Browse latest Browse all 27417

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>