I use the function to check timestamps on files on remote computers. We have a lot of computers.
What I'm launching is a little strange.
I am running a query on a large number of computers. Timestamp on computer26887 appears as "1/4/2013 12:46:01 AM" I UNC on this computer and check the file. In the explorer, the time stamp says "9/16/2013 11:23" (one and a half hours ago) Hmmm .... The request again is the same old, incorrect, time stamp. I right-click on the file, go to properties and click "Details" in the properties window - "Modified on 9/16/2013 11:23 AM" Request again with vb code - now it shows the correct timestamp ????
I have hundreds of systems to go through, and if I can’t trust the data that I get, I have too much work!
Any ideas?
Update
Basically, VB.NET retrieves the cached version of the timestamp. The timestamp is updated, but the cache still has the old timestamp. How to make the cache update without manually opening the file properties in Explorer?
Shared Function GetFileInfo(ByVal ComputerName As String, ByVal FiletoFind As String, info As String) Dim Ret As String = "" Dim targetfile = "\\" & ComputerName & "\" & FiletoFind Dim fi As FileInfo = New FileInfo(targetfile) If fi.Exists Then fi.refresh Select Case info Case Is = "Exists" Ret = fi.Exists.ToString Case Is = "Delete" fi.Delete() Ret = fi.Exists.ToString Case Is = "Created" Ret = fi.CreationTime.ToString("MM/dd/yyyy hh:mm:ss tt") Case Is = "Access" Ret = fi.LastAccessTime.ToString("MM/dd/yyyy hh:mm:ss tt") Case Is = "Mod" Ret = fi.LastWriteTime.ToString("MM/dd/yyyy hh:mm:ss tt") End Select Else Ret = "File Not Found" End If Ret = Ret.Replace(vbCrLf, "") Ret = Ret.Replace(vbCr, "") Return Ret End Function
(I also tried using File
, not FileInfo
... to check message history)
UPDATE
As a test, I checked the file check on the system using AutoIT3 code. He returned the exact information. After checking AutoIT3, vb.net returned the exact timestamps. So what is the problem with vb.net that AutoIT3 does a better job?
Func _timestampchk($path) Dim $file,$astamp $file = $path $astamp = FileGetTime($file, 0, 0) If IsArray($astamp) Then $stamp = $astamp[1] & "/" & $astamp[2] & "/" & $astamp[0] & " " & $astamp[3] & ":" & $astamp[4] ElseIf $astamp = 0 Then $stamp = "File " & $path & " not Found" Else $stamp = 0 EndIf Return $stamp EndFunc ;==>_timestampchk