Jump to content

Getting File date (last modified) from a file that's opened for writing


 Share

Recommended Posts

I need to check if files have been modified, while another application has them opened for writing, windows can do it, why can't winapi ? Is there any way to do it ?

It wil only show date and time once it was saved. This example Notepad is buzy modifying the test.txt file. Once it is saved the correct time and date will be shown.

$time =  FileGetTime("Test.txt", 0); 0 if for modified date

If Not @error Then
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[2]& "/" & $time[1] & "/" & $time[0]
    MsgBox(0, "Modify date and time of notepad.exe", $dmyyyy)
EndIf
Link to comment
Share on other sites

It wil only show date and time once it was saved. This example Notepad is buzy modifying the test.txt file. Once it is saved the correct time and date will be shown.

$time =  FileGetTime("Test.txt", 0); 0 if for modified date

If Not @error Then
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[2]& "/" & $time[1] & "/" & $time[0]
    MsgBox(0, "Modify date and time of notepad.exe", $dmyyyy)
EndIf

FileGetTime can't be used on files that are currently opened by another application... will set @error to 1 every time
Link to comment
Share on other sites

FileGetTime can't be used on files that are currently opened by another application... will set @error to 1 every time

This will not give you a message if there is a error.

Is it not working for you?

$file = FileOpen("test.txt", 2)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileWrite($file, "Do a Test Line 1" & @CRLF)
FileWrite($file, "Line2" & @CRLF)
FileWrite($file, "Line3" & @CRLF)
FileClose($file)
ShellExecute ( "test.txt")
Sleep(1000)
$time =  FileGetTime("Test.txt", 0); 0 if for modified date
If Not @error Then
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[2]& "/" & $time[1] & "/" & $time[0]
    MsgBox(0, "Modify date and time of notepad.exe", "Info while test.txt is open: " & $dmyyyy)
EndIf
Link to comment
Share on other sites

This will not give you a message if there is a error.

Is it not working for you?

$file = FileOpen("test.txt", 2)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileWrite($file, "Do a Test Line 1" & @CRLF)
FileWrite($file, "Line2" & @CRLF)
FileWrite($file, "Line3" & @CRLF)
FileClose($file)
ShellExecute ( "test.txt")
Sleep(1000)
$time =  FileGetTime("Test.txt", 0); 0 if for modified date
If Not @error Then
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[2]& "/" & $time[1] & "/" & $time[0]
    MsgBox(0, "Modify date and time of notepad.exe", "Info while test.txt is open: " & $dmyyyy)
EndIf

y that works, but why does this:

$search = FileFindFirstFile("C:\Program Files (x86)\Minecraft\world\region\*.mcr")
if @error Then
    MsgBox(0, "error", "failed to find first file")
    Exit
EndIf
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    ConsoleWrite("File:" & $file & @CRLF)

    $time = FileGetTime($file)
    if @error Then
        ConsoleWrite("Error getting time from " & $file & @CRLF)
    EndIf

WEnd

; Close the search handle
FileClose($search)

give

File:r.-1.-1.mcr
Error getting time from r.-1.-1.mcr
File:r.-1.-2.mcr
Error getting time from r.-1.-2.mcr
File:r.-1.0.mcr
Error getting time from r.-1.0.mcr
File:r.-2.-1.mcr
Error getting time from r.-2.-1.mcr
File:r.-2.-2.mcr
Error getting time from r.-2.-2.mcr
File:r.-2.0.mcr
Error getting time from r.-2.0.mcr
File:r.0.-1.mcr
Error getting time from r.0.-1.mcr
File:r.0.-2.mcr
Error getting time from r.0.-2.mcr
File:r.0.0.mcr
Error getting time from r.0.0.mcr
File:r.0.1.mcr
Error getting time from r.0.1.mcr
File:r.1.-1.mcr
Error getting time from r.1.-1.mcr
File:r.1.0.mcr
Error getting time from r.1.0.mcr

EDIT: LOL, Sorry I'm retarded... Never mind, thanks for your help :)

Edited by pixartist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...