Jump to content

List Files with Time


antmar904
 Share

Recommended Posts

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

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

  • Moderators

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

"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

  • Moderators

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

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

#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

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

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

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

 

Link to comment
Share on other sites

  • Developers
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

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