antmar904

List Files with Time

17 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

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)

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
#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

 

Share this post


Link to post
Share on other sites

That would be because you are reading from the wrong array.

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

Glad you worked it out :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by antmar904

Share this post


Link to post
Share on other sites

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"

#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

 

Share this post


Link to post
Share on other sites

Bump :)

Share this post


Link to post
Share on other sites
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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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! :)

Share this post


Link to post
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