Jump to content
Sign in to follow this  
Damastah

substituting command line commands in AutoIT

Recommended Posts

Damastah

I want to create an autoIt version of Dir. This is what i have so far.

Func listFolders()
    If FileExists("Dir.txt") then FileDelete("dir.txt")
    $search = FileFindFirstFile($directory & "*.*")  

;Check if the search was successful
;If $search = -1 Then Exit
    

    While 1
        $file = FileFindNextFile($search) 
    ;If @error Then ExitLoop
If StringInStr($file, ".", 2, -4) then MsgBox(0, @error, $file);FileWriteLine("Dir.txt", $file); if there is no Extention, meaning folder...Does not work for folders with "." in name
WEnd

; Close the search handle
    FileClose($search)
    
EndFunc

The second code box is what im having problems with. My goal is to check 4 places from the end, (or the 3 char extentions E.G: ".txt") to see if there is a "." in that place. This will help me get around possible directory names with periods in them, and not have my program mistake it for a file. I either want to fix this "algorithm" or get an alternative to the command line's Dir command with all its switches.

Share this post


Link to post
Share on other sites
Triblade

This function: FileGetAttrib($filename)

can show if the given input is a file or directory.

String returned could contain a combination of these letters "RASHNDOCT":
"R" = READONLY
"A" = ARCHIVE
"S" = SYSTEM
"H" = HIDDEN
"N" = NORMAL
"D" = DIRECTORY  <----!!!
"O" = OFFLINE
"C" = COMPRESSED (NTFS compression, not ZIP compression)
"T" = TEMPORARY

Maybe this helps you somewhat.

I am not clear if you say your code does or does not work.

Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites
PsaltyDS

There are many examples of _FileListToArray() with and without recursion. Search is your friend.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Damastah

My code does NOT work.

Share this post


Link to post
Share on other sites
PsaltyDS

...

; if there is no Extention, meaning folder...

...

Where did you get this silly assumption? Drop this foolishness and determine file/directory by the attributes (as per Triblade), or use _FileListToArray() to only the ones you want (as suggested by me).

As for your function:

Func listFolders()
    If FileExists("Dir.txt") Then FileDelete("dir.txt")
    $search = FileFindFirstFile($directory & "*.*")
    While 1
        $file = FileFindNextFile($search)
        If StringInStr($file, ".", 2, -4) Then MsgBox(0, @error, $file)
    WEnd
    FileClose($search)
EndFunc  ;==>listFolders

... what sets $directory? What is the handling for trailing "\" on the path? What exits from the While/WEnd loop?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Damastah

Thanx TriBlade for the reference. It's going to help me solve all my problems with my DIR conversion.

I fixed the code to be:

While 1
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        $attrib = FileGetAttrib($directory & $file)
        if StringInStr($attrib, "D")then
            MsgBox(0, $file, $attrib)
            if $attrib = "D" then FileWriteLine("Dir.txt", $file
            EndIf
    WEnd
Edited by Damastah

Share this post


Link to post
Share on other sites
Triblade

If the above code gives error's (and I think you've probably allready noticed if you run this code)

then its because: FileWriteLine("Dir.txt", $file

See, you miss a closing ) :)


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

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  

×