Jump to content

_FileListToArray + "last modified" time stamp


Recommended Posts

Hello all,

in my previous topic i started a script which is writing files from a specific directory into a simple TXT file.

Now I want my script to be able to get a little more information from those files and write them all into a TXT file.

I want file name + last modified date to be written.

The only usefull stuff i found on help was function called FileGetTime() but i dont know how to combine it with my _FileListToArray() function.

Any help would be greatly apreciated.

Thx

#include <Array.au3>
#include <File.au3>

$File = "c:\Filenames.dat"  

$Path = $CmdLine[1]                 

$List = _FileListToArray($Path)     
FileDelete("c:\Filenames.dat")
sleep(200)
_FileWriteFromArray($File, $List, 1)
Link to comment
Share on other sites

Dump the _FileWriteFromArray() garbage and use a loop coupled with FileWriteLine() and FileGetTime()

For $i = 1 To Ubound($List) -1
  ;; Do what you want here.
Next

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Dump the _FileWriteFromArray() garbage and use a loop coupled with FileWriteLine() and FileGetTime()

For $i = 1 To Ubound($List) -1
  ;; Do what you want here.
Next

Hello,

thanks for replay.

I have encountered another problem. (see my script below)

#include <Array.au3>
#include <File.au3>


$File = "C:\File.dat"
$Command = $CmdLine[1]
$List = _FileListToArray($Command)
$file_open = FileOpen($File, 2)

$time =  FileGetTime($List)

For $i = 1 To Ubound($List) -1

    $t = FileGetTime($List[$i])
    $yyyymd = $t[2] & "." & $t[1] & "." & $t[0] & " " & $t[3] & "." & $t[4]
    FileWriteLine($file_open,$list[$i] & "     " & FileGetTime($List[$i]) & @CRLF)

Next

I think the problem is that _FileListToArray function only writes file names to array and no other information....

Anyway the problem i have now is that i dont know how to pick up file by file from a directory and write it to TXT file.

Link to comment
Share on other sites

Thats what _FileListToArray() does and the primary reason I won't use it.

#include <Array.au3>

#include <File.au3>

$File = "C:\File.dat"

$Command = $CmdLine[1]

$List = _FileListToArray($Command)

If StringRight($Command, 1) <> "\" Then $Command &= "\"

$file_open = FileOpen($File, 2)

;;$time = FileGetTime($List);;;;;;; Totally useless, $List isn't a file

For $i = 1 To Ubound($List) -1

$sFile = $Command & $List[$i]

$t = FileGetTime($sFile)

$yyyymd = $t[2] & "." & $t[1] & "." & $t[0] & " " & $t[3] & "." & $t[4]

FileWriteLine($file_open,$sFile & " " & FileGetTime($sFile) & @CRLF)

Next

FileClose($File_open) ;; Very important to close a file handle after you finish writing to it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hello again,

i manage to solve it by my self actually. I used _FileListToArray to get number of files and their names. Then i compared stored names in array with names on directory. If name exists in array then i read time of it with FileGetTime and write both time and Name into a TXT file.

Thank you very much for your reply!

PS thx for that FileClose($File_open) tip i would forgot to do that 100%.

Link to comment
Share on other sites

  • 6 years later...
On 17/06/2010 at 3:15 AM, amakrkr said:

Hello again,

 

i manage to solve it by my self actually. I used _FileListToArray to get number of files and their names. Then i compared stored names in array with names on directory. If name exists in array then i read time of it with FileGetTime and write both time and Name into a TXT file.

 

Thank you very much for your reply!

 

 

PS thx for that FileClose($File_open) tip i would forgot to do that 100%.

 

about posting the code may help someone in the future, don't you think ?

Link to comment
Share on other sites

You do realize this is a 7 year old post?

To get FileList with FileTime you could use:

#include <Array.au3>
#include <File.au3>

Local $sFilePath = @ScriptDir
Local $aFilePath = _FileListToArrayRec($sFilePath, "*", 1, 0, 0, 2)
If @error Then Exit

Local $aFileTime[1][2]
For $i = 1 To $aFilePath[0]
    _ArrayAdd($aFileTime, $aFilePath[$i] & "|" & FileGetTime($aFilePath[$i], 0, 1))
Next
_ArrayDisplay($aFileTime)

 

Link to comment
Share on other sites

14 minutes ago, Subz said:

You do realize this is a 7 year old post?

To get FileList with FileTime you could use:

#include <Array.au3>
#include <File.au3>

Local $sFilePath = @ScriptDir
Local $aFilePath = _FileListToArrayRec($sFilePath, "*", 1, 0, 0, 2)
If @error Then Exit

Local $aFileTime[1][2]
For $i = 1 To $aFilePath[0]
    _ArrayAdd($aFileTime, $aFilePath[$i] & "|" & FileGetTime($aFilePath[$i], 0, 1))
Next
_ArrayDisplay($aFileTime)

 

 

thanks, that is exactly what  I wanted.

Link to comment
Share on other sites

#include <Array.au3>
#include <File.au3>

Local $sFilePath = @ScriptDir
Local $aFilePath = _FileListToArrayRec($sFilePath, "*", 1, 0, 0, 2)
If @error Then Exit

Local $aFileTime[1][2]
For $i = 1 To $aFilePath[0]
    _ArrayAdd($aFileTime, $aFilePath[$i] & "|" & FileGetTime($aFilePath[$i], 0, 1))
Next

_ArraySort ($aFileTime,1,1,"",1)   ;sort by date
_ArrayDisplay($aFileTime)

sort by date more recent 

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