Jump to content

Error in detecting directory attribute


Recommended Posts

When this bit of script runs, the console shows that directories that FileGetAttrib() is run on are returning empty strings, instead of strings that contain a D. What could be causing this?

 

While 1
    $file = FileFindNextFile($filehandle)
    If @error Then
        ConsoleWrite("Error in SearchDir") ;
        ExitLoop
    EndIf

    $aPathSplit = _PathSplit($file, $sDrive, $sDir, $sFileName, $sExtension)

    If $file <> '.' And $file <> '..' Then
        $att = FileGetAttrib($file) ;$dir &  $file)

        ConsoleWrite("              SearchDir is examining " & $file & "which is " & $att & @CRLF)

        If StringInStr($att, "D") > 0 Then ;<------ checks if file is a directory
            SearchDir($dir & "\" & $file, $dirToCheck)
            FileChangeDir($dir)

        EndIf
    EndIf
WEnd

 

Link to comment
Share on other sites

This works perfect for me:

#include <File.au3>
Local  $sDrive, $sDir, $sFileName, $sExtension
$filehandle=FileFindFirstFile('*.*')
While 1
    $file = FileFindNextFile($filehandle)
    If @error Then
        ConsoleWrite("Error in SearchDir") ;
        ExitLoop
    EndIf
    ConsoleWrite($file)

    $aPathSplit = _PathSplit($file, $sDrive, $sDir, $sFileName, $sExtension)

    If $file <> '.' And $file <> '..' Then
        $att = FileGetAttrib($file) ;$dir &  $file)

        ConsoleWrite("              SearchDir is examining " & $file & "which is " & $att & @CRLF)

        If StringInStr($att, "D") > 0 Then ;<------ checks if file is a directory
            ;SearchDir($sdir & "\" & $sfile, $dirToCheck)
            FileChangeDir($sdir)
            ConsoleWrite('Dir Changed'&@CRLF)
            ;Exit
        EndIf
    EndIf
WEnd

seems you used wrong var $dir instead of $sDir.

Link to comment
Share on other sites

46 minutes ago, AutoBert said:

This works perfect for me:

#include <File.au3>
Local  $sDrive, $sDir, $sFileName, $sExtension
$filehandle=FileFindFirstFile('*.*')
While 1
    $file = FileFindNextFile($filehandle)
    If @error Then
        ConsoleWrite("Error in SearchDir") ;
        ExitLoop
    EndIf
    ConsoleWrite($file)

    $aPathSplit = _PathSplit($file, $sDrive, $sDir, $sFileName, $sExtension)

    If $file <> '.' And $file <> '..' Then
        $att = FileGetAttrib($file) ;$dir &  $file)

        ConsoleWrite("              SearchDir is examining " & $file & "which is " & $att & @CRLF)

        If StringInStr($att, "D") > 0 Then ;<------ checks if file is a directory
            ;SearchDir($sdir & "\" & $sfile, $dirToCheck)
            FileChangeDir($sdir)
            ConsoleWrite('Dir Changed'&@CRLF)
            ;Exit
        EndIf
    EndIf
WEnd

seems you used wrong var $dir instead of $sDir.

That's actually just referring to a variable declared outside the while loop which is redundant (they're one in the same).

I know that the thing causing my problem is that this recursive function is calling another recursive function. If I cancel the other, the program works as intended. But I'd have to post the entire 400 line code to show what I mean, which nobody wants to look through. 

Thanks for the help, and for confirming the problem is not happening in this particular loop

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