Damastah Posted June 26, 2008 Share Posted June 26, 2008 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 ExitLoopIf 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 nameWEnd ; Close the search handle FileClose($search) EndFuncThe 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. Link to comment Share on other sites More sharing options...
Triblade Posted June 26, 2008 Share Posted June 26, 2008 (edited) 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 June 26, 2008 by Triblade My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger) Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 26, 2008 Share Posted June 26, 2008 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 Link to comment Share on other sites More sharing options...
Damastah Posted June 26, 2008 Author Share Posted June 26, 2008 My code does NOT work. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 26, 2008 Share Posted June 26, 2008 ... ; 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 Link to comment Share on other sites More sharing options...
Damastah Posted June 26, 2008 Author Share Posted June 26, 2008 (edited) 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 June 26, 2008 by Damastah Link to comment Share on other sites More sharing options...
Triblade Posted June 27, 2008 Share Posted June 27, 2008 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) 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