cypher175 Posted November 7, 2008 Posted November 7, 2008 How Can I set a variable from all the Folder names located in a Specified Directory..?? I need to do something like this.. Where a message box pops up with every Folders Name inside a Specified Directory.. $FolderName = GetDirNames(@ProgramFilesDir) For $i = 1 to $FolderName[0] ;MsgBox(0,"",$FolderName[$i]) How would I do something like that..??
senthor Posted November 7, 2008 Posted November 7, 2008 (edited) Hi! Do it like this... expandcollapse popup#include <array.au3> SplashTextOn("", "Listing directions...", 150, 20, -1,-1, 51) $FolderName = _FileListTreeToArray(@ProgramFilesDir, 1, "D") SplashOff() _ArrayDisplay($FolderName) ; #FUNCTION# ================================================================ ; Name...........: _FileListTreeToArray ; Description ...: List all files from the wished directiry with all files from all subfolders to an array. ; Syntax.........: _FileListTreeToArray($sPath[, $fRelation = 1[, $sType = ""[,$sSort = "N"]]]) ; Parameters ....: $sPath - Path to the directory that has to be listed ; $fRelation - Optional: Path return type, "0" = absolute (default), "1" = relative ; $sType - Optional: Search type, see helptopic "FileGetAttrib"; possible : "RASHD", with "-" before for negotation: ; |R - Readonly ; |A - Archive ; |S - System ; |H - Hidden ; |D - Directory ; $sSort - Optional: Sort results, see "cmd.exe /K dir /?" at subpoint "order", with "-" before for negotation: possibilities: ; |N - Name, alphabetically ; |S - Size, smaller files first ; |E - Extension, alphabetically ; |D - Date/Time, older files first ; |G - Directories first ; Return values .: Success - Array with $array[0] = Number of items, $array[n] = path of items ; Failure - Returns 0 and Sets @Error: ; |0 - No error. ; |1 - Invalid $sPath ; |2 - Invalid $fRelation ; |3 - Invalid $sType ; |4 - Invalid $sSort ; |5 - User32.dll failure ; Author ........: Jonas Neef ; Remarks .......: Caution: This function can take very long! Wildcards are supported. ; Related .......: FileGetAttrib, FileSetAttrib, _FileListToArray ; Link ..........; ; Example .......; Yes ; =========================================================================== Func _FileListTreeToArray($sPath, $fRelation = 0, $sType = "", $sSort = "N") local $aCheck, $vStdout, $sTemp, $sPlaceholder, $sTempSort, $vStdout, $sLine, $iCounter, $aReturn ; Check parameters, validate path $aCheck = StringLeft($sPath, 3) $aCheck = StringSplit($aCheck, ":" ) If $aCheck[0] <> 2 and StringLeft($sPath, 1) <> "\" then $sPath = @WorkingDir & "\" & $sPath If $aCheck[0] <> 2 and StringLeft($sPath, 1) = "\" then $sPath = @WorkingDir & $sPath If StringRight($sPath, 1) = "\" then $sPath = StringTrimRight($sPath, 1) If Not FileExists($sPath) then Return Seterror(1, 0, 0) if $fRelation > 1 OR $fRelation < 0 then return Seterror(2, 0, 0) $sTempSort = StringReplace($sSort, "-", "") If StringLen($sTempSort) <> 1 or _ $sTempSort <> "N" and _ $sTempSort <> "S" and _ $sTempSort <> "E" and _ $sTempSort <> "D" and _ $sTempSort <> "G" and _ $sTempSort <> "" then _ return Seterror(3, 0, 0) If Stringreplace( _ Stringreplace( _ Stringreplace( _ Stringreplace( _ Stringreplace( _ Stringreplace($sType, "-", "") _ , "H", "") _ , "S", ""), _ "A", ""), _ "R", ""), _ "D", "") <> "" then _ return Seterror(4,0,0) ; Start CMD to load the tree If $sType = "" Then $vStdout = Run(@comspec & ' /C cd ..\..\..\..\.. & dir "' & $sPath & '" /A /B /O:' & $sSort & ' /S', @workingdir, @SW_HIDE, 6) Else $vStdout = Run(@comspec & ' /C cd ..\..\..\..\.. & dir "' & $sPath & '" /A:' & $sType & ' /B /O:' & $sSort & ' /S', @workingdir, @SW_HIDE, 6) EndIF ; Get data via Stdout While 1 $sLine = StdoutRead($vStdout) If @error Then ExitLoop If $sLine <> "" then $sTemp &= $sLine Wend ; Create Placeholder for hole string For $iCounter = 0 To StringLen($sTemp) $sPlaceholder &= " " Next ; Convert string from extended Ascii to Ansi $sTemp = DllCall("user32.dll", "long", "OemToChar", "str", $sTemp, "str", $sPlaceholder) $sPlaceholder = "" If Not Isarray($sTemp) or $sTemp[0] < 1 then return Seterror(5,0,0) $sTemp = $sTemp[2] ; Format finally $sTemp = StringReplace($sTemp, @crlf, @lf) $sTemp = StringReplace($sTemp, @cr, @lf) If StringRight($sTemp, 1) = @lf then $sTemp = StringTrimRight($sTemp, 1) If StringLeft($sTemp, 1) = @lf then $sTemp = StringTrimLeft($sTemp, 1) If Not StringInStr($sTemp, @lf) then If $sTemp = "" then local $aReturn[1] = [0] Else local $aReturn[2] = [1, $sTemp] EndIf Else local $aReturn = StringSplit($sTemp, @lf) EndIF if not isarray($aReturn) then Return Seterror(5,0,0) EndIF ; If relative path is chosen edit the paths If $fRelation = 1 Then For $iCounter = 1 To $aReturn[0] Step 1 $aReturn[$iCounter] = StringReplace($aReturn[$iCounter], $sPath & "\", "") Next EndIf ; Return array return Seterror(0,0,$aReturn) EndFunc ;==>_FileListTreeToArray senthor Edited November 7, 2008 by senthor FileListToArray UDFMy tools
Danny35d Posted November 7, 2008 Posted November 7, 2008 Search the help file for _FileListToArray. #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray(@DesktopDir, '*', 2) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList") AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Danny35d Posted November 7, 2008 Posted November 7, 2008 Search the help file for _FileListToArray. #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray(@DesktopDir, '*', 2) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList") AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Andreik Posted November 7, 2008 Posted November 7, 2008 (edited) #include <File.au3> $DIR = FileSelectFolder("SELECT","") $DIRS = _FileListToArray($DIR,2) If IsArray($DIRS) Then For $INDEX = 1 To $DIRS[0] MsgBox(0,"DIRS",$DIRS[$INDEX]) Next EndIf Edited November 7, 2008 by Andreik
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