Jump to content

Recommended Posts

My problem will be described below, but this is my full script.

Dim $search, $file
Dim $dirSize, $dirFile
Dim $i, $line, $attrib


;Opens the file to write the desired output to.
$dirFile = FileOpen("output.txt", 1)

If $dirFile = -1 Then
    MsgBox(0, "Error", "The file output.txt was unable to be opened.")
    Exit
EndIf

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile("C:\*.*")  

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

;MsgBox(0, "$search", $search)

While 1
    $file = FileFindNextFile($search)
   ;MsgBox(0, "$file", $file)
    Sleep(10)
    If @error Then
    MsgBox(0, "Error", "There are no more files/directories")
    ExitLoop
    EndIf
    
    $attrib = FileGetAttrib($file)
        Sleep(10)
    If @error Then
        MsgBox(4096,"Error", "Could not obtain attributes.")
        Exit
    Else
        If StringInStr($attrib, "D") Then
            $dirSize = DirGetSize($file, 1)
            $line = "Filename: " & $file & "   " & "DirSize(MB): " & Round($dirSize[0]/1024/1024) & "   " & "NumFiles: " & $dirSize[1] & "   " & "NumDirectories: " & $dirSize[2]
            FileWriteLine($dirFile, $line)
        EndIf
    EndIf
WEnd

; Close the search handle
FileClose($search)
FileClose($dirFile)

Most of the above code is straight from the help file. All of the If statements that check @error are erroring out, but when I have the Sleep(10) in there it doesnt error, but my program never stops because it never catches the @error function.

I did try using a message box to see if it was really erroring out or not, but it showed it really didnt error.

$file = FileFindNextFile($search)
    MsgBox(0, "$file", $file)
    If @error Then
    MsgBox(0, "Error", "There are no more files/directories")
    ExitLoop
    EndIf

Without the message box that errors everytime. This is copied straight out of the helpfile. I cant help but to think there is something I have done.

Any help would be much appreciated.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to post
Share on other sites

Dim $search, $file
Dim $dirSize, $dirFile, $dir = "c:\"
Dim $i, $line, $attrib


;Opens the file to write the desired output to.
$dirFile = FileOpen("output.txt", 1)

If $dirFile = -1 Then
    MsgBox(0, "Error", "The file output.txt was unable to be opened.")
    Exit
EndIf

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile($dir & "*.*")  

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

;MsgBox(0, "$search", $search)

While 1
    $file = FileFindNextFile($search)
   If @error Then
        MsgBox(0, "Error", "There are no more files/directories")
        ExitLoop
    EndIf
   $attrib = FileGetAttrib($dir & $file)
    If $attrib == "" Then
        MsgBox(4096,"Error", "Could not obtain attributes from " & $file)
;~       Exit
    Else
        If StringInStr($attrib, "D") Then
            $dirSize = DirGetSize($dir & $file, 1)
            $line = "Filename: " & $file & "   " & "DirSize(MB): " & Round($dirSize[0]/1024/1024) & "   " & "NumFiles: " & $dirSize[1] & "   " & "NumDirectories: " & $dirSize[2]
            FileWriteLine($dirFile, $line)
        EndIf
    EndIf
WEnd

; Close the search handle
FileClose($search)
FileClose($dirFile)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to post
Share on other sites

That did it. I guess that should be changed in the helpfile or something.

Thanks,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...