Jump to content
Sign in to follow this  
andguent

$timeStamp = FileGetTime(FileFindFirstFile) no go

Recommended Posts

When I run the code below, I get:

$yyyymmddhhmmss = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]

$yyyymmddhhmmss = $t^ ERROR

Error: Subscript used with non-Array variable.

I would like to create a string that contains timestamps of all files in a particular directory. If I statically assign the file for FileGetTime to check, then it works. Will FileGetTime not accept file handles from FileFindFirstFile?

Thanks.

Local $strPathToCheck = "C:\Program Files\MyStuff"
Local $strFileListing = ""

$fileListing = FileFindFirstFile($strPathToCheck & '\*.*')  

;; Check if the search was successful
If $fileListing = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

;MsgBox(0, "First file", "First file is: " & $strFileName)

While 1
    $file = FileFindNextFile($fileListing)
    If @error Then ExitLoop

    MsgBox(4096, "File:", $strPathToCheck & "\" & $file, 1)
    $t = FileGetTime($file, 1)
    $yyyymmddhhmmss = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
    $strFileListing = $strFileListing & $file & " " & $yyyymmddhhmmss & " ";& ' \n'


WEnd

MsgBox(4096, "FileListing:", $strFileListing)

; Close the search handle
FileClose($fileListing)

Share this post


Link to post
Share on other sites

From experience:

The first 2 matches that FileFindNextFile returns are:

.

..

When you use an invalid filename as a parameter for FileGetTime it fails and doesn't return an array <- that happened

What you need to do, is use error checking.

Change:

$t = FileGetTime($file, 1)

to:

$t = FileGetTime($file, 1)
If @error Then ContinueLoop

Share this post


Link to post
Share on other sites

$t = FileGetTime($file, 1)

This line also needs to be changed to:

$t = FileGetTime($strPathToCheck & "\" & $file, 1)

It needs to full path to the file to get the info unless it's in the same directory with the script.

You Can Also change the following to work around FileFind returning "." and ".."

From:

$file = FileFindNextFile($fileListing)
    If @error Then ExitLoop

To:

$file = FileFindNextFile($fileListing)
    If $file = "." or $file = ".." Then ContinueLoop
    If @error Then ExitLoop

We have enough youth. How about a fountain of SMART?

Share this post


Link to post
Share on other sites

Thanks. The ContinueLoop did it with some minor additions.

While 1
    $file = FileFindNextFile($fileListing)
    If @error Then ExitLoop
    
    If ($file == "." OR $file == "..") Then
        ContinueLoop
    EndIf

;MsgBox(4096, "File:", $file, 1)
;MsgBox(4096, "File:", $strPathToCheck & "\" & $file, 1)
    $t = FileGetTime($strPathToCheck & "\" & $file, 1)
    $yyyymmddhhmmss = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
    $strFileListing = $strFileListing & $file & " " & $yyyymmddhhmmss & " ";& ' \n'
;MsgBox(4096, "FileListing:", $strFileListing)


WEnd

Share this post


Link to post
Share on other sites

Thanks. The ContinueLoop did it with some minor additions.

$t = FileGetTime($strPathToCheck & "\" & $file, 1)
I'd add in a error check after $t...but that could be just anal retentive...

$t = FileGetTime($strPathToCheck & "\" & $file, 1)
   If not IsArray($t) then
      MsgBox(0,"Error Trap","$t is not an array")
     ; Call Exit Function (if any)
   EndIf

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...