antmar904 Posted September 25, 2017 Share Posted September 25, 2017 Hi All, I need to list all files in the current folder and all sub folders and get the time for each file. Then I need to copy each file who's time is from 1/1/2015 to present to a different folder. I am using _FileListToArrayRec to get the file names and path but I'm having issues getting the files times and writing all this info to a .csv file. Here is what I have so far. #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find () Func Find () ;Write file name and path to csv $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) _FileWriteFromArray(@ScriptDir & "\_FileArrayList.csv", $aFileList) ;Write file time to csv $aFileTime = FileGetTime($aFileList) _FileWriteFromArray(@ScriptDir & "\_FileArraryList.csv", $aFileTime) ;Debug ;_ArrayDisplay($aArray) EndFunc Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 UPDATE: #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find () Func Find () ;Write file name and path to csv $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) _FileWriteFromArray(@ScriptDir & "\_FileArrayList.csv", $aFileList) ;Loop through files and get modified time $Time = "" For $i = 1 To UBound($aFileList, 1) - 1 $Time = FileGetTime($aFileList[$i], $FT_MODIFIED) FileWriteLine(@ScriptDir & "\test.txt", $Time) Next ;Debug ;_ArrayDisplay($aArray) EndFunc Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 25, 2017 Moderators Share Posted September 25, 2017 (edited) Not surprising that you are getting no response, as the help file states for the first parameter: Quote The path to the file or directory to check. You cannot simply pass it an array. You have to create your array, then loop through the indices and get the time. Edit: I see you came to the same conclusion Edited September 25, 2017 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 @JLogan3o13 Yes, thanks for the heads up. I'm still unable to get the "Created" time. How can I write both the file name with path and the modified time to the same csv file so I can then check which file was created after January 1 2014? Thanks again for your help. I'm still chipping away at this. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 25, 2017 Moderators Share Posted September 25, 2017 Personal preference, but I would get it into your array first (usually easier to manipulate) and then add the array to your csv. Something like this: #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) Next _ArrayDisplay($aFinal) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 I'm having trouble reading the Time column in the array: #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find() Func Find() #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) Next If $aFileList[$a][1] > "20150101" Then MsgBox(0, "", $aFileList[$a]) EndIf _ArrayDisplay($aFinal) EndFunc ;==>Find Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find() Func Find() #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) If $aFileList[1] > "20170922999999" Then MsgBox(0, "", $aFileList[$a]) EndIf Next _ArrayDisplay($aFinal) EndFunc ;==>Find Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 25, 2017 Moderators Share Posted September 25, 2017 That would be because you are reading from the wrong array. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 I've tried many things, can't seem to read the correct array. #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find() Func Find() #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) Next For $i = 0 To UBound($aFinal[2]) - 1 If $i > "20170924999999" Then MsgBox(0, "", $aFinal[0][$a]) EndIf Next _ArrayDisplay($aFinal) EndFunc ;==>Find Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 I think I got it @JLogan3o13' #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find() Func Find() #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) Next For $i = 1 To UBound($aFinal) - 1 If $aFinal[$i][1] > "20170925111750" Then MsgBox(0, "", $aFinal[$i][0]) EndIf Next _ArrayDisplay($aFinal) EndFunc ;==>Find Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 25, 2017 Moderators Share Posted September 25, 2017 Glad you worked it out "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 having some issues with the copy syntax RunWait(@ComSpec & ' /c copy '& @ScriptDir & "\" & $aFinal[$i][0] "C:\Temp\_Move\", "", @SW_HIDE) Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 (edited) This seems to be working #RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find() Func Find() Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) Next For $i = 1 To UBound($aFinal) - 1 If $aFinal[$i][1] > "20170925111750" Then MsgBox(0, "", @ScriptDir & "\" & $aFinal[$i][0]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') cmd:' & @ComSpec & ' /c copy "' & @ScriptDir & "\" & $aFinal[$i][0] & '"' & " " & '"' & "C:\Temp\_Move\" & '"' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console RunWait(@ComSpec & ' /c copy "' & @ScriptDir & "\" & $aFinal[$i][0] & '"' & " " & '"' & "C:\Temp\_Move\" & '"', "", @SW_HIDE) EndIf Next _ArrayDisplay($aFinal) EndFunc ;==>Find Edited September 25, 2017 by antmar904 Link to comment Share on other sites More sharing options...
antmar904 Posted September 25, 2017 Author Share Posted September 25, 2017 So it looks like _FileListToArrayRec is not returning all file names. Here is a file path: E:\_TempRestore\Joe Abdiii\Users\abcdefahi\Desktop\This is a folder name\PMP\2016\Shab, Rob VC.pdf Here is what is being written to my: PMP\2016\Shab <--- Missing the rest of the file name "Shab, Rob VC.pdf" expandcollapse popup#RequireAdmin #include <File.au3> #include <Array.au3> #include <FileConstants.au3> Find() Func Find() DirCreate(@ScriptDir & "\_RestoredFiles") Local $aFinal[1][2] $aFinal[0][0] = "File" $aFinal[0][1] = "Time" $aFileList = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_RELPATH) For $a = 1 To $aFileList[0] _ArrayAdd($aFinal, $aFileList[$a] & "|" & FileGetTime(@ScriptDir & "\" & $aFileList[$a], $FT_CREATED, $FT_STRING)) Next _FileWriteFromArray(@ScriptDir & "\_RestoredFiles\_FileList.csv", $aFinal) For $i = 1 To UBound($aFinal) - 1 If $aFinal[$i][1] > "20140101050099" Then ;MsgBox(0, "", @ScriptDir & "\" & $aFinal[$i][0]) ;Debug ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') cmd:' & @ComSpec & ' /c copy "' & @ScriptDir & "\" & $aFinal[$i][0] & '"' & " " & '"' & "C:\Temp\_Move\" & '"' & @CRLF & '>Error code: ' & @error & @CRLF) ;Debug Console RunWait(@ComSpec & ' /c copy "' & @ScriptDir & "\" & $aFinal[$i][0] & '"' & " " & '"' & @ScriptDir & "\_RestoredFiles" & '"', "", @SW_HIDE) FileWriteLine(@ScriptDir & "\_RestoredFiles\_FilesCopied.csv", $aFinal[$i][0]) EndIf Next MsgBox(0, "", "File search done!") ;Debug to see array ;_ArrayDisplay($aFinal) EndFunc ;==>Find Link to comment Share on other sites More sharing options...
antmar904 Posted September 26, 2017 Author Share Posted September 26, 2017 Bump Link to comment Share on other sites More sharing options...
Developers Jos Posted September 26, 2017 Developers Share Posted September 26, 2017 2 hours ago, antmar904 said: Bump Not sure why you feel the need to bump the thread already? Waiting at least 24 hours would be nice. So you mean that the part of the filename is missing in file "_FilesCopied.csv"? How are you opening this file as it has a CommaSeparateValues extension and the part that is missing starts with a comma? JOs SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
antmar904 Posted September 26, 2017 Author Share Posted September 26, 2017 Ah Thanks @Jos I changed the file type to .xls and all is working now. Ill be sure to wait 24 hrs before giving a bump! 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