newbiescripter Posted February 1, 2008 Author Posted February 1, 2008 Thanks for your help randallc, but I can't make it work will you try replace your line in the code below? I've tryid replacing the If StringRight but it comes op with an error :/ expandcollapse popup#include <array.au3>;Only needed for array display ;Root folder to begin search $folder = FileSelectFolder("Find the folder including your text files to combine", "", 2 ) If @error = 1 Then Exit ;Recursive search for txt (or TXT) files only $Array = RecursiveFileSearch($folder, "(?i)\.(txt)\z") ;If any files were found If $Array[0] > 0 Then ;_ArrayDisplay($Array) ;Output destination $save = FileSaveDialog("Select were to save your file" , "" , "Text files (*.txt)" , 16 ) If @error = 1 Then Exit $output = FileOpen($save, 1) $seperator = @CRLF & @CRLF & "----------------New TXT file----------------" & @CRLF & @CRLF ;Loop through found files For $X = 1 to $Array[0] $file = FileRead($Array[$X]) FileWrite($output, $file & $seperator) Next EndIf ;RFSstartdir: Path to starting folder ;RFSpattern: RegEx pattern to match i.e. "(?i)\.(mp3)" find all mp3 files - case insensitive, "(?-i)\.(mp3|txt)" find all mp3 and txt files - case sensitive ;RFSrecurse: TRUE = Recursive, FALSE = Non-recursive ;RFSdepth: Internal use only Func RecursiveFileSearch($RFSstartDir, $RFSpattern = ".", $RFSrecurse = true, $RFSdepth = 0) ;Ensure starting folder has a trailing slash If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\" If $RFSdepth = 0 Then ;Get count of all files in subfolders for initial array definition $RFSfilecount = DirGetSize($RFSstartDir, 1) Global $RFSarray[$RFSfilecount[1] + 1] EndIf $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*") If @error Then Return ;Search through all files and folders in directory While 1 $RFSnext = FileFindNextFile($RFSsearch) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then If $RFSrecurse Then RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSpattern, $RFSrecurse, $RFSdepth + 1) Else If StringRegExp($RFSnext, $RFSpattern, 0) Then ;Append filename to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext ;Increment filecount $RFSarray[0] += 1 EndIf EndIf WEnd FileClose($RFSsearch) If $RFSdepth = 0 Then Redim $RFSarray[$RFSarray[0] + 1] Return $RFSarray EndIf EndFunc ;==>RecursiveFileSearch Thanks for your help and time
randallc Posted February 1, 2008 Posted February 1, 2008 Hi, Sorry, it was "@Cameronsdad's" scrip to which I should have been referring!; Nevertheless, in this one, just replace lines 24 and 25 to get rid of the "chr(0)" characters; I have not checked if there are any others that would not write?; ;Loop through found files to read, remove nulls, then append / save to 1 file For $X = 1 to $Array[0] $file = FileRead($Array[$X]) FileWrite($output, $file & $seperator) NextoÝ÷ Ù·¢g¬jëh×6 For $X = 1 to $Array[0] ;~ $file = FileRead($Array[$X]) $file = StringReplace(FileRead($Array[$X]),chr(0),"") FileWrite($output, $file & $seperator) NextI have not tested the recursion, but if it was already working, this will strip any chr(0), I believe. Good luck, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
bluebearr Posted February 1, 2008 Posted February 1, 2008 (edited) You know, I think that I might be tempted to do a batch file like this (for all the files in the directory C:\temp\test): del c:\temp\AllTestFiles.txt for /R c:\temp\test %%a in (*.*) do type %%a>>c:\temp\AllTestFiles.txt In AutoIt, this would become (with prompts and such): #include <Process.au3> $folder = FileSelectFolder("Find the folder including your text files to combine", "", 2 ) $save = FileSaveDialog("Select where to save your file" , "" , "Text files (*.txt)" , 16 ) _RunDOS('del "' & $save & '" & for /R "' & $folder & '" %a in (*.*) do type %a>>"' & $save & '"') Edited February 2, 2008 by bluebearr BlueBearrOddly enough, this is what I do for fun.
newbiescripter Posted February 3, 2008 Author Posted February 3, 2008 Sorry, but now I've tryid so much and cannot make it work :/ is it possible that one of you could place your solution in the script and then post it all in here? I couldn't make the one with placing line 24 and 25 to work. Hope you can help Regards
randallc Posted February 3, 2008 Posted February 3, 2008 Sorry, but now I've tryid so much and cannot make it work :/ is it possible that one of you could place your solution in the script and then post it all in here? I couldn't make the one with placing line 24 and 25 to work. Hope you can help RegardsHi, This worked for me; expandcollapse popup; weaponxnull.au3 #include <array.au3>;Only needed for array display ;Root folder to begin search ;~ $folder = FileSelectFolder("Find the folder including your text files to combine", "", 2 ) ;~ If @error = 1 Then Exit $folder = @ScriptDir&"\91 50" ;Recursive search for txt (or TXT) files only $Array = RecursiveFileSearch($folder, "(?i)\.(txt)\z") ;If any files were found If $Array[0] > 0 Then ;_ArrayDisplay($Array) ;Output destination ;~ $save = FileSaveDialog("Select were to save your file" , "" , "Text files (*.txt)" , 16 ) ;~ If @error = 1 Then Exit $save = @ScriptDir&"\_Backup\netview.txt" $output = FileOpen($save, 1) $seperator = @CRLF & @CRLF & "----------------New TXT file----------------" & @CRLF & @CRLF ;Loop through found files to read, remove nulls, then append / save to 1 file For $X = 1 to $Array[0] ;~ $file = FileRead($Array[$X]) $file = StringReplace(FileRead($Array[$X]),chr(0),"") FileWrite($output, $file & $seperator) Next EndIf ;RFSstartdir: Path to starting folder ;RFSpattern: RegEx pattern to match i.e. "(?i)\.(mp3)" find all mp3 files - case insensitive, "(?-i)\.(mp3|txt)" find all mp3 and txt files - case sensitive ;RFSrecurse: TRUE = Recursive, FALSE = Non-recursive ;RFSdepth: Internal use only Func RecursiveFileSearch($RFSstartDir, $RFSpattern = ".", $RFSrecurse = true, $RFSdepth = 0) ;Ensure starting folder has a trailing slash If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\" If $RFSdepth = 0 Then ;Get count of all files in subfolders for initial array definition $RFSfilecount = DirGetSize($RFSstartDir, 1) Global $RFSarray[$RFSfilecount[1] + 1] EndIf $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*") If @error Then Return ;Search through all files and folders in directory While 1 $RFSnext = FileFindNextFile($RFSsearch) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then If $RFSrecurse Then RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSpattern, $RFSrecurse, $RFSdepth + 1) Else If StringRegExp($RFSnext, $RFSpattern, 0) Then ;Append filename to array $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext ;Increment filecount $RFSarray[0] += 1 EndIf EndIf WEnd FileClose($RFSsearch) If $RFSdepth = 0 Then Redim $RFSarray[$RFSarray[0] + 1] Return $RFSarray EndIf EndFunc ;==>RecursiveFileSearchBest, randall [note I hard coded where my files lay] - the dos solution did not work.. ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
JustinReno Posted February 3, 2008 Posted February 3, 2008 I'm not sure if this is what you are asking, but, why not just use _FileListToArray()? Or, FileReadToArray() & FileWriteFromArray(). And Generator made a simple and small script to take all text files into a directory and put them all into one text file with a divider between each file: #Include <File.au3> $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt")
randallc Posted February 3, 2008 Posted February 3, 2008 I'm not sure if this is what you are asking, but, why not just use _FileListToArray()? Or, FileReadToArray() & FileWriteFromArray(). And Generator made a simple and small script to take all text files into a directory and put them all into one text file with a divider between each file: #Include <File.au3> $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt")Hi, Well, 1. my script is tested and works, yours does not. 2. He has "null" characters in his files which stop your script from working. [read the thread.............] Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
newbiescripter Posted February 3, 2008 Author Posted February 3, 2008 Thanks I've tryid it and it works. I've made some small changes, but you're right it doesn't has the "null" characters and that was what I was looking for
newbiescripter Posted February 3, 2008 Author Posted February 3, 2008 Thanks for you help Randall.. I've made some small changes, such as the @WorkingDir and a little more, but i was wondering is it possible to take the text files in the subfolders into the all_files also? Just like WeaponX's script does? Regards
randallc Posted February 3, 2008 Posted February 3, 2008 Thanks for you help Randall.. I've made some small changes, such as the @WorkingDir and a little more, but i was wondering is it possible to take the text files in the subfolders into the all_files also? Just like WeaponX's script does? Regards Hi, Try FillistToArrayNew link in my sig for recursive UDF; #include-once #include<Array.au3> #include<FileListToArray3.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 local $sPath1 = @ScriptDir, $filter = "a*.txt" ; $filter = "*.txt" to get all text files in subdirs Local $ar_Array = _FileListToArray3($sPath1, $filter, 1, 1, 1);,"",0) ;_FileListToArrayRecurse($sPath, $sFilter = "*", $iFlag = 0) _ArrayDisplay($ar_Array) $save = @ScriptDir & "\_Backup\netview.txt" $output = FileOpen($save, 1) $seperator = @CRLF & @CRLF & "----------------New TXT file----------------" & @CRLF & @CRLF ;Loop through found files to read, remove nulls, then append / save to 1 file For $X = 1 To $ar_Array[0] ;~ $file = FileRead($Array[$X]) $file = StringReplace(FileRead($ar_Array[$X]), Chr(0), "") FileWrite($output, $file & $seperator) Next run("notepad "&$save)Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
newbiescripter Posted February 3, 2008 Author Posted February 3, 2008 Nice work with the FileListToArray3.au3 I can see that its finding the text in the subfolders, but how do i puch it all together with this: ? #Include <File.au3> $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt")
randallc Posted February 4, 2008 Posted February 4, 2008 (edited) Nice work with the FileListToArray3.au3 I can see that its finding the text in the subfolders, but how do i puch it all together with this: ?Hi,I am not sure what your problem is? ; The script I gave you works for me; what else do you need?Best, Randall Edited February 4, 2008 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
newbiescripter Posted February 4, 2008 Author Posted February 4, 2008 Yes you are right the script below works, but it doesn't collect the text files from the subfolders #Include <File.au3> $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt") Then I was asking how to collect the text files from the subfolders also and you showed me this script: #include-once #include<Array.au3> #include<FileListToArray3.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 local $sPath1 = @ScriptDir, $filter = "a*.txt"; $filter = "*.txt" to get all text files in subdirs Local $ar_Array = _FileListToArray3($sPath1, $filter, 1, 1, 1);,"",0);_FileListToArrayRecurse($sPath, $sFilter = "*", $iFlag = 0) _ArrayDisplay($ar_Array) $save = @ScriptDir & "\_Backup\netview.txt" $output = FileOpen($save, 1) $seperator = @CRLF & @CRLF & "----------------New TXT file----------------" & @CRLF & @CRLF ;Loop through found files to read, remove nulls, then append / save to 1 file For $X = 1 To $ar_Array[0] ;~ $file = FileRead($Array[$X]) $file = StringReplace(FileRead($ar_Array[$X]), Chr(0), "") FileWrite($output, $file & $seperator) Next run("notepad "&$save) But how do I put this together with the first one above? so that the script you gave me first also collect the txt files from the subfolder. If I use your first script it will collect all txt files from the @WorkingDir, but it won't collect the text files from the subfolder, then you showed me the second and it's finding the text files in the subfolders also, but it doesn't combine them in a large txt file. So I ask how do I set up the to scripts together so that the finally script will collect all .txt files from the current folder and its subfolders and then put them all together in one large .txt file? I hope you know what I mean or else you may ask again. I'm glad that you're helping.. Regards
randallc Posted February 4, 2008 Posted February 4, 2008 Yes you are right the script below works, but it doesn't collect the text files from the subfoldersfinding the text files in the subfolders also, but it doesn't combine them in a large txt file.Hi,Of course it does work; it puts them all in 1 file; what is your problem?I have used a filter to keep the file small; note "a.txt"; make it what you will..Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
newbiescripter Posted February 4, 2008 Author Posted February 4, 2008 The problem is that the Script below doesn't include the txt files from the subfolders.. How do I make it do that? #Include <File.au3> $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt") In Post #30 you told me but I didn't understand so I ask you again. How do I make the Script include the subfolders also? because this one doesn't collect txt files from the subfolders also.
randallc Posted February 4, 2008 Posted February 4, 2008 Hi, Look at the parameters in the UDF file; #include<FileListToArray3.au3> local $sPath1 = @ScriptDir, $filter = "a*.txt"; $filter = "*.txt" to get all text files in subdirs Local $ar_Array = _FileListToArray3($sPath1, $filter, 1, 1, 1);,"",Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
newbiescripter Posted February 8, 2008 Author Posted February 8, 2008 Hey Randall now I've tried for long time and have this: #include<FileListToArray3.au3> #Include <File.au3> local $sPath1 = @ScriptDir, $filter = "a*.txt"; $filter = "*.txt" to get all text files in subdirs Local $ar_Array = _FileListToArray3($sPath1, $filter, 1, 1, 1);,"", $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt") But it will still not collect the text from the subfolders.. I really don't know why.. How would you exactly make it so you can collect the text file from the subfolders also and then combine them into one ? Regards
randallc Posted February 8, 2008 Posted February 8, 2008 Hi, I am still not sure why you did not just modify my working script! Anyway, #include<FileListToArray3.au3> #Include <File.au3> #Include <array.au3> Local $Location = @DesktopDir & "\", $sFileResult = $Location & "All_Files.txt";to write Local $sPath1 = @ScriptDir, $filter = "*.txt"; $filter = "*.txt" to get all text files in subdirs Local $FileList = _FileListToArray3($sPath1, $filter, 1, 1, 1);,"", ;~ $FileList = _FileListToArray($Location) ; what are you trying to do with this line? ConsoleWrite("Number of Files; $FileList[0]=" & $FileList[0] & @LF) _ArrayDisplay($FileList, "$FileList") If $FileList[0] = 0 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $hOpener = FileOpen($sFileResult, 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) FileWrite($hOpener, FileRead($FileList[$X])); filelist alreasdy has base directory in string; $Location FileWrite($hOpener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $X & @CRLF & @CRLF) Next FileClose($hOpener); ShellExecute($Location & "All_Files.txt")oÝ÷ ئlº·¬¶)eÂÊëkÊ)à¶hÂ+a¶¬)Þjëh×6$FileList = _FileListToArray($Location) ; what are you trying to do with this line?Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
newbiescripter Posted February 9, 2008 Author Posted February 9, 2008 Okay what I'm trying to do collect all txt file In a folder including all its subfolder. If we say it should collect all .txt file from the scriptdir, then it should take i from both Scriptdir Scriptdir/subfolder1 Scriptdir/subfolder1/subfolder2 Hope you understand what I mean.. the problem with the code below, is that it doesn't include the .txt files from the subfolders nomather what I do. can you make it do that? if you can then please post it in here, so that I can see how you are doing it. Heres the code that is working fine in the folder, but doesn't include the subfolder. maybe you can modify it so it also INCLUDE the text files from the SUBfolders #Include <File.au3> $Location = @DesktopDir&"\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) For $X = 1 To UBound($FileList) - 1 ToolTip("File #" & $X, 10, 10, "Tecter", 1) If StringInStr($FileList[$X], ".txt") Then FileWrite($Opener, FileRead($Location & $FileList[$x])) FileWrite($Opener, @CRLF & @CRLF & "************* Divider **************** File Number = " & $x & @CRLF & @CRLF) EndIf Next FileClose($Opener) ShellExecute($Location & "All_Files.txt") Thanks for your help Regards
randallc Posted February 9, 2008 Posted February 9, 2008 (edited) Okay what I'm trying to do collect all txt file In a folder including all its subfolder. If we say it should collect all .txt file from the scriptdir, then it should take i from both Scriptdir Scriptdir/subfolder1 Scriptdir/subfolder1/subfolder2 Hope you understand what I mean.. the problem with the code below, is that it doesn't include the .txt files from the subfolders nomather what I do. can you make it do that? if you can then please post it in here, so that I can see how you are doing it. Heres the code that is working fine in the folder, but doesn't include the subfolder. maybe you can modify it so it also INCLUDE the text files from the SUBfolders Thanks for your help RegardsHi, You have asked the same question muiltiple times, and I have posted scripts which do just what you asked at least 3x; last time in post # 38! What is the problem here? Are you just fooling with me? The lines you have missing from your script at the moment [if youy will at least look and compare] are; #include<FileListToArray3.au3> Local $sPath1 = @ScriptDir, $filter = "*.txt"; $filter = "*.txt" to get all text files in subdirs Local $FileList = _FileListToArray3($sPath1, $filter, 1, 1, 1);,"",oÝ÷ Ù.Â)eëÞ®¶¬¹·è׫²'ò¢ë¬y«¢+Ù1½°ÀÌØí¥±1¥ÍÐô}¥±1¥ÍÑQ½ÉÉä ÀÌØíÍAÑ Ä¤ì°ÅÕ½ÐìÅÕ½Ðì°oÝ÷ Ú¶êí©ÚºÚ"µÍØØ[ ÌÍÑ[SÝHÑ[SÝÐ^LÊ ÌÍÜÔ]K ÌÍÙ[KKJNË ][ÝÉ][ÝË, and to do so, you need to iclude my UDF as posted in the zip from the previous posts or the link in my signature. What are you finding so difficult to understand here? Randall Edited February 9, 2008 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
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