bhargavik Posted April 25, 2013 Share Posted April 25, 2013 hey , i need to get the time for a particular file,i did this but its not showing the time . this is my code .. please help me Local $win = @ScriptDir &"\Test\*.log" $ch= FileFindFirstFile($win) While 1 Local $file = FileFindNextFile($ch) If @error Then ExitLoop MsgBox(4096, "File:", $file) WEnd Local $t = FileGetTime($file) If Not @error Then Local $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2] MsgBox(0, "Creation date of notepad.exe", $yyyymd) EndIf Link to comment Share on other sites More sharing options...
OliverA Posted April 25, 2013 Share Posted April 25, 2013 (edited) Use AUTOIT CODE! Two ways of many ways: #include <File.au3> ; _FileListToArray Find_with_Array() Find_Without_Array() Func Find_with_Array() Local $search = _FileListToArray(@ScriptDir, "*.jpg", 1) ; Only for files If @error = 4 Then ; File not found MsgBox(16, "Error", "Files not found") Return EndIf For $x = 1 To $search[0] Local $t = FileGetTime(@ScriptDir & "\" & $search[$x], 1) MsgBox(0, "Creation date of " & $search[$x], $t[0] & "/" & $t[1] & "/" & $t[2]) Next EndFunc ;==>Find_with_Array Func Find_Without_Array() Local $search_v2 = FileFindFirstFile(@ScriptDir & "\" & "*.jpg") If $search_v2 = -1 Then ; File not found MsgBox(16, "Error", "Files not found") Return EndIf While 1 Local $file = FileFindNextFile($search_v2) If @error Then ExitLoop Local $t = FileGetTime($file, 1) MsgBox(0, "Creation date of " & $file, $t[0] & "/" & $t[1] & "/" & $t[2]) WEnd EndFunc ;==>Find_Without_Array Edited April 25, 2013 by OliverA I'M QUIT FROM THIS FORUM! It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself. In what way? It's easy...just search on google For that people, wish you the best way, Oliver Astone Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2013 Moderators Share Posted April 25, 2013 (edited) bhargavik,Why use the clumsy FileFindFirst/NextFile combo when there is a UDF to all the work for you? This should do the trick: #include <Array.au3> #include <File.au3> $sRoot = @ScriptDir & "\Test" $sMask = "*.log" $aList = _FileListToArray($sRoot, $sMask, 1) Global $aFileTime[UBound($aList)][2] For $i = 1 To $aList[0] $aTime = FileGetTime($sRoot & "\" & $aList[$i]) $aFileTime[$i][0] = $aList[$i] $aFileTime[$i][1] = $aTime[0] & "/" & $aTime[1] & "/" & $aTime[2] Next _ArrayDisplay($aFileTime)All clear? M23 Edited April 25, 2013 by Melba23 Amended code - see below Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted April 25, 2013 Share Posted April 25, 2013 (edited) The reason it was not working is because you search until an error occurs (If @error Then ExitLoop). After the error occurs you try to use the search information which failed The creation time of the failed file search name doesn't exist. I might as well post my example even though I'm too late. #include <File.au3> Local $win = @ScriptDir &"\Test\" Local $aFileList = _FileListToArray($win, "*.log", 1) Local $t, $yyyymd For $i = 1 To $aFileList[0] $t = FileGetTime($win & $aFileList[$i]) $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2] MsgBox(0, "Creation date of " & $aFileList[$i], $yyyymd) Next @Melba Your code contains a slight oversight. Edited April 25, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2013 Moderators Share Posted April 25, 2013 czardas, Your code contains a slight oversightDo you mean I should have done this: Global $aFileTime[UBound($aList)][2] = [[$aList[0]]] to fill the [0] element? If not, then pray do tell. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted April 25, 2013 Share Posted April 25, 2013 (edited) When you call FileGetTime(), the relative path to the file is missing the root folder - unless I'm mistaken and the behaviour of this function has changed in a recent version (maybe beta). Edited April 25, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2013 Moderators Share Posted April 25, 2013 czardas,You are quite correct - thanks for pointing it out. I was testing on files within @ScriptDir and so did not notice. Above post amended. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted April 25, 2013 Share Posted April 25, 2013 Your example is clearer than mine. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
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