pixartist Posted February 23, 2011 Posted February 23, 2011 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 ?
JoHanatCent Posted February 23, 2011 Posted February 23, 2011 On 2/23/2011 at 2:14 AM, 'pixartist said: 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
pixartist Posted February 23, 2011 Author Posted February 23, 2011 On 2/23/2011 at 3:50 AM, 'JoHanatCent said: 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
JoHanatCent Posted February 23, 2011 Posted February 23, 2011 On 2/23/2011 at 4:10 AM, 'pixartist said: 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
pixartist Posted February 23, 2011 Author Posted February 23, 2011 (edited) On 2/23/2011 at 5:38 AM, 'JoHanatCent said: 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 February 23, 2011 by pixartist
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now