kor Posted March 26, 2010 Share Posted March 26, 2010 #Include <File.au3> #Include <Array.au3> $sPath = @ScriptDir $FileList=_FileListToArray($sPath, '*', 2) $company = InputBox("test", "Company Name?", "", " M") $destination = InputBox("test1", "Destination Drive Letter?", "", " M1") If @Error=1 Then MsgBox (0,"Error","No Files\Folders Found.") Exit EndIf $iElement = "0" _ArrayDelete($FileList, $iElement) $File = $company & ".bat" _FileWriteFromArray($File, $FileList) ; Display results Run("notepad.exe " & $File) I've gotten this far, but I want to add the full path to the directories in the file. Also, if I could somehow add another string to the beginning of each line, and at the end of each line that would be awesome too, but I haven't gotten that far yet I know I need to do some kind of file read loop kinda thing but I'm not really sure how to move forward. Link to comment Share on other sites More sharing options...
KaFu Posted March 26, 2010 Share Posted March 26, 2010 add this $lineprefix = "" $linesufix = "" for $i = 0 to UBound($FileList)-1 $FileList($i) = $lineprefix & $sPath & "\" & $FileList($i) & $linesufix Next after the _arraydelete(). Set pre- and sufix to whatever you need... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
GEOSoft Posted March 26, 2010 Share Posted March 26, 2010 If it's just folders that you are after then try this function. It returns the full path with a trailing backslash and it's (optionally) recursive. expandcollapse popup;=============================================================================== ; Function Name: _Fldr_ListToArray() ; Description: Recursivly find the folders in a given path (returns full path for each) ; Syntax: _Fldr_ListToArray($s_Path[, $b_Recurse[, $b_Hidden[, $b_System]]]) ; Parameter(s): $s_Path - The base folder ; $s_Ignore - Pipe (|) separated list of folders to ignore. The * wildcard is accepted. ; $b_Recurse - If True (default) search is recursive ; $b_Hidden - If False (default) "Hidden" folders are NOT included ; $b_System If True (default) "System" folders are included. ; Requirements: ; Return Value(s): Success - A 0 based array of the folders with paths ; Failure - Sets @Error to 1 ; Author(s): George (GEOSoft) Gedye ; Notes: ;Example(s): #cs ;; folders in C:\, non-recursive Excluding the Windows folder and including Hidden and System folders $aArray = _Fldr_ListToArray("c:", "Windows", True) _ArrayDisplay($aArray) #ce ;=============================================================================== Func _Fldr_ListToArray($s_Path, $s_Ignore = "", $b_Recurse = True, $b_Hidden = False, $b_System = True) If StringRight($s_Path, 1) <> "\" Then $s_Path &= "\" $s_Path = '"' & $s_Path & '"' Local $s_Working = @WorkingDir, $s_Env = "" FileChangeDir(@TempDir) Local $sFile = "dir.txt" If FileExists($sFile) Then FileDelete($sFile) If $b_Recurse Then $s_Env &= " /s" $s_Env &= " /b /o:n" Local $s_Attrib = " /a:d" If NOT $b_Hidden Then $s_Attrib &= "-h" If NOT $b_System Then $s_Attrib &= "-s" $s_Env &= $s_Attrib EnvSet("DIRCMD", $s_Env) $hPID = Run(@ComSpec & ' /c dir ' & $s_Path & " > " & $sFile , "", @SW_HIDE, 0x02) While ProcessExists($hPID) If @error Then ExitLoop WEnd Local $s_Str = StringStripWS(FileRead($sFile), 2) FileDelete($sFile) EnvSet("DIRCMD", "") FileChangeDir($s_Working) If $s_Str Then If $s_Ignore Then $aIgnore = StringSplit($s_Ignore, "|", 2) For $i = 0 To UBound($aIgnore) -1 $aIgnore[$i] = StringRegExpReplace($aIgnore[$i], "\.*\*+", "\.\*\?") $s_Str = StringRegExpReplace($s_Str, "(?i)(?m:^).+\\" & $aIgnore[$i] & "\\.*(?:\z|\v)+", "") Next EndIf $a_Fldrs = StringRegExp($s_Str, "(?i)(?m:^)(.+)(?:\v|$)+", 3) If Not @error Then For $i = 0 To UBound($a_Fldrs) -1 $a_Fldrs[$i] &= "\" Next Return $a_Fldrs EndIf EndIf Return SetError(1) EndFunc ;;<===>_Fldr_ListToArray George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
kor Posted March 26, 2010 Author Share Posted March 26, 2010 add this $lineprefix = "" $linesufix = "" for $i = 0 to UBound($FileList)-1 $FileList($i) = $lineprefix & $sPath & "\" & $FileList($i) & $linesufix Next after the _arraydelete(). Set pre- and sufix to whatever you need... >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\filelist.au3" C:\filelist.au3 (21) : ==> Expected a "=" operator in assignment statement.: $FileList($i) = $lineprefix & $sPath & "\" & $FileList($i) & $linesufix $FileList^ ERROR >Exit code: 1 Time: 2.119 Link to comment Share on other sites More sharing options...
Fire Posted March 26, 2010 Share Posted March 26, 2010 Here is one too:(If i understand correct?) #include <File.au3> #include <Array.au3> Dim $avarray ;$company = InputBox("test", "Company Name?", "", " M") $destination = InputBox("Enter Drive Letter","Enter Drive Letter","") RunWait("cmd.exe /c " & "dir /B " & $destination & " >"&@TempDir&"\tempfile.dat",@ScriptDir,@SW_HIDE) _FileReadToArray(@TempDir&"\tempfile.dat",$avarray) For $x=0 To $avarray[0] MsgBox(64,"",FileGetLongName($destination&$avarray[$x])) Next [size="5"] [/size] Link to comment Share on other sites More sharing options...
kor Posted March 26, 2010 Author Share Posted March 26, 2010 Kafu, I got the script to run by adding Step at the end of your For To loop for $i = 0 to UBound($FileList) Step -1 which allows the script to run, but it is not actually adding the paths, prefix or suffix to the lines. Link to comment Share on other sites More sharing options...
99ojo Posted March 26, 2010 Share Posted March 26, 2010 (edited) Hi,it looks like a typo:$FileList ($i) should be $FileList [$i], shouldn't it, as it adresses an array element?And the Step - 1 doesn't make any sense as you run from 0 to 50 (e.g) Step -1 ???;-))Stefan Edited March 26, 2010 by 99ojo Link to comment Share on other sites More sharing options...
kor Posted March 26, 2010 Author Share Posted March 26, 2010 #Include <File.au3> #Include <Array.au3> $Path = @ScriptDir $Folders=_FileListToArray($Path, '*', 2) Dim $avarray $company = InputBox("", "Company Name?", "", " M") $destination = InputBox("", "Destination Drive Letter?", "", " M1") $File = $company & ".bat" If @Error=1 Then MsgBox (0,"Error","No Files\Folders Found.") Exit EndIf $count = "0" _ArrayDelete($Folders, $count) _ArrayDisplay($Folders) For $i = 0 to UBound($Folders) Step -1 $Folders[$i] = "test\" & $Folders($i) Next _FileWriteFromArray($File, $Folders) ; Display results Run("notepad.exe " & $File) I've changed the code a little, and changed the names of the VAR's to make them less confusing to me. Everything is working except the actual modification of the array lines. It spits out the list of folders, but it isn't adding the "test" in front of them. (or at all) Link to comment Share on other sites More sharing options...
99ojo Posted March 26, 2010 Share Posted March 26, 2010 (edited) Hi, you haven't read carefully: For $i = 0 to UBound($Folders) Step -1 should be For $i = 0 to UBound($Folders) - 1 Then it should run as expected. Stefan Edited March 26, 2010 by 99ojo Link to comment Share on other sites More sharing options...
kor Posted March 26, 2010 Author Share Posted March 26, 2010 Man, I'm so stupid. I was about to reply and say I've already tried that and it didnt work, but I didn't have a space between ($Folders) -1, mine was ($Folders)-1 thank you so much! Link to comment Share on other sites More sharing options...
kor Posted March 26, 2010 Author Share Posted March 26, 2010 (edited) Final Code expandcollapse popup#Include <File.au3> #Include <Array.au3> $Path = @ScriptDir $Folders=_FileListToArray($Path, '*', 2) $company = InputBox("Robocopy Maker", "Company Name?", "", " M") $destinationdrive = InputBox("Robocopy Maker", "Destination Drive Letter?", "", " M1") $File = $company & ".bat" ; Remove drive letter from Path $workingpath = StringTrimLeft($Path, 1) ; Combine to form new destination directory $destinationpath = $destinationdrive & $workingpath ; Error checking If @Error=1 Then MsgBox (0,"Error","No Files\Folders Found.") Exit EndIf ; Trim folder count from array $count = "0" _ArrayDelete($Folders, $count) ;_ArrayDisplay($Folders) ; Pre and Post commands $pre = "start robocopy " $post = " /E /DCOPY:T" For $i = 0 to UBound($Folders) -1 $Folders[$i] = $pre & $Path & $Folders[$i] & " " & $destinationpath & $Folders[$i] & $post Next _FileWriteFromArray($File, $Folders) ; Display results Run("notepad.exe " & $File) Edited March 26, 2010 by kor Link to comment Share on other sites More sharing options...
KaFu Posted March 27, 2010 Share Posted March 27, 2010 $FileList ($i) should be $FileList [$i], shouldn't it, as it adresses an array element? Doooh, me bad ...typo... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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