Styler001 Posted September 10, 2007 Share Posted September 10, 2007 I really struggled over whether I should dredge up a year-old topic that had some relevant suggestions, or starting up a new topic. I'm still not sure a new topic was the best way to go, but here it is anyway. I've got between 200 and 300 text files that I want to merge into one. There is no commonality between the filenames, other than the TXT extension. Nothing like FILE1.TXT, FILE2.TXT, FILE3.TXT, etc. Each file pretty much has a completely different filename. This isn't the actual list, but filenames could be as different as CATS.TXT, DOGS.TXT, RACING.TXT, DIRT.TXT. So no way of simply saying something like: Append fileX.txt through fileY.txt into fileZ.txt They are, however, all in the same directory. I know I can accomplish the basic append through the DOS prompt, but that just crams all of the text files into one seemless file. I'd like to be able to put some kind of divider in between each file to differentiate between them so each "section" would be easier to recognize. I've found a program called UUMERGE that will put a divider in place, but it's little better than the DOS copy I mentioned above. Is there a good way to do this in AutoIt? Link to comment Share on other sites More sharing options...
Siao Posted September 10, 2007 Share Posted September 10, 2007 (edited) Open Autoit Help file and read about: _FileListToArray() or FileFindFirstFile/FileFindNextFile For loop FileRead() FileWrite() Edited September 10, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Valuater Posted September 10, 2007 Share Posted September 10, 2007 This should do the trick #Include <File.au3> $Location = "C:\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) ; #2 replaces old text 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") 8) Link to comment Share on other sites More sharing options...
Styler001 Posted September 10, 2007 Author Share Posted September 10, 2007 Thanks, Siao, for the hints. And thanks, Valuater, for the script. I wasn't expecting anyone to write one for me, but I do appreciate it. It's been awhile since I've done anything with AutoIt, so I was not looking forward to struggling through relearning what I might've forgotten. Your script works perfectly. Thanks again. Link to comment Share on other sites More sharing options...
Valuater Posted September 10, 2007 Share Posted September 10, 2007 ... Your script works perfectly. Thanks again. Welcome8) Link to comment Share on other sites More sharing options...
gfunk999 Posted October 23, 2007 Share Posted October 23, 2007 (edited) Isn't there an easier way to do this with autoit? with batch code you can just run this code on a command line or a batch... type *.txt >> "c:\backup\%username%.backup.txt" type *.txt ;reads all text files >> ;appends read files to %username%.backup.txt file This should do the trick #Include <File.au3> $Location = "C:\" $FileList = _FileListToArray($Location) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf $Opener = FileOpen($Location & "All_Files.txt", 2) ; #2 replaces old text 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") 8) Edited October 23, 2007 by gfunk999 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 23, 2007 Moderators Share Posted October 23, 2007 Isn't there an easier way to do this with autoit? with batch code you can just run this code on a command line or a batch... type *.txt >> "c:\backup\%username%.backup.txt" type *.txt ;reads all text files >> ;appends read files to %username%.backup.txt fileI would imagine your request to look something like this: _DirFileAppend(@UserName & "\Au3Files\", "*.au3", @UserName & "\Au3Files\AU3.BACK.log", 1) Func _DirFileAppend($sDir, $sMod, $sBackDir, $bWait = 0) If StringRight($sDir, 1) <> "\" Then $sDir &= "\" If StringLeft($sMod, 1) = "\" Then $sMod = StringTrimLeft($sMod, 1) If $bWait Then Return RunWait(@Comspec & ' /c type "' & _ $sDir & $sMod & '" >> "' & $sBackDir & '"', '', @SW_HIDE) Return Run(@Comspec & ' /c type "' & _ $sDir & $sMod & '" >> "' & $sBackDir & '"', '', @SW_HIDE) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
gfunk999 Posted October 23, 2007 Share Posted October 23, 2007 (edited) Can we do it like this... I think it's a lot easier, but I may be wrong... It works #include <Process.au3> Run(@ComSpec & " " & "/c" & " " & "type" & " " & @TempDir & "\*.txt" & " " & ">>" & " " & "c:\backup\%username%.backup.txt", "", @SW_HIDE) %username% is called from the built-in command environment variable or we could always replace it with @username Edited October 23, 2007 by gfunk999 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 23, 2007 Moderators Share Posted October 23, 2007 Can we do it like this... I think it's a lot easier, but I may be wrong... It works #include <Process.au3> Run(@ComSpec & " " & "/c" & " " & "type" & " " & @TempDir & "\*.txt" & " " & ">>" & " " & "c:\backup\%username%.backup.txt", "", @SW_HIDE) %username% is called from the built-in command environment variable or we could always replace it with @usernameWhy is that easier... you've put unnecessary ampersands and limited yourself on where your output file would be. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
gfunk999 Posted October 24, 2007 Share Posted October 24, 2007 Oh I see your point, it makes sense now. I thought my way was easier, but I had a feeling it was not practical. Why is that easier... you've put unnecessary ampersands and limited yourself on where your output file would be. 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