andguent Posted March 7, 2005 Share Posted March 7, 2005 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) Link to comment Share on other sites More sharing options...
SlimShady Posted March 7, 2005 Share Posted March 7, 2005 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 Link to comment Share on other sites More sharing options...
sykes Posted March 7, 2005 Share Posted March 7, 2005 $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? Link to comment Share on other sites More sharing options...
andguent Posted March 7, 2005 Author Share Posted March 7, 2005 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 Link to comment Share on other sites More sharing options...
Blue_Drache Posted March 7, 2005 Share Posted March 7, 2005 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 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