Dieuz Posted March 26, 2008 Share Posted March 26, 2008 (edited) Hi, I was wondering if there is any code outhere that will do the following things: Let's say I have a 1000 .txt file with text in it. I want to run a code that will copy every text in those files and paste it all in 1 big .txt file. If nobody made a code for that, I might start one. Thanks in advance, Edited March 26, 2008 by Dieuz Link to comment Share on other sites More sharing options...
JustinReno Posted March 26, 2008 Share Posted March 26, 2008 (edited) I made one:At the top of your script, make sure you #Include<Misc.au3>http://quadryders.com/phpcc/snippet.php?sid=98 Edited March 26, 2008 by Jardenix Link to comment Share on other sites More sharing options...
narayanjr Posted March 26, 2008 Share Posted March 26, 2008 FileRead FileWrite _FileListToArray Link to comment Share on other sites More sharing options...
Dieuz Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks Jardenix, how long would it take to copy let's say 1000 files with 10k words in each one. Link to comment Share on other sites More sharing options...
JustinReno Posted March 26, 2008 Share Posted March 26, 2008 I'm not sure, just a minute... Link to comment Share on other sites More sharing options...
Dieuz Posted March 26, 2008 Author Share Posted March 26, 2008 kk I will test it right now! Thanks alot again! Link to comment Share on other sites More sharing options...
JustinReno Posted March 26, 2008 Share Posted March 26, 2008 It took me around 7.6 seconds. And sorry, its #Include <File.au3> not Misc! Link to comment Share on other sites More sharing options...
JustinReno Posted March 26, 2008 Share Posted March 26, 2008 This is the example I used: #Include <File.au3> Global $String, $H_GetTextFiles DirCreate(@ScriptDir & "\Test") For $I = 1 To 10000 $String &= 1 Next For $I = 1 To 1000 FileWrite(@ScriptDir & "\Test\" & $I & ".txt", $String) Next _TextFileMerger(@ScriptDir & "\Test", @ScriptDir & "\Test\All.txt") Func _TextFileMerger($H_FolderPath, $H_OutPutFilePath, $V_ExecuteWhenDone = 0) ;$Timer = TimerInit() $H_GetTextFiles = _FileListToArray($H_FolderPath, "*.txt") For $I = 1 To $H_GetTextFiles[0] $S_GetTextFileData = FileRead($H_FolderPath & "\" & $H_GetTextFiles[$I]) FileWrite($H_OutPutFilePath, " ***" & $H_GetTextFiles[$I] & "***" & @CRLF) FileWrite($H_OutPutFilePath, $S_GetTextFileData) FileWrite($H_OutPutFilePath, @CRLF & "***** Text File Divider *****" & @CRLF) Next ;MsgBox(0, "", TimerDiff($Timer) / 1000) If $V_ExecuteWhenDone = 1 Then ShellExecute($H_OutPutFilePath) EndFunc For $I = 1 To $H_GetTextFiles[0] FileDelete(@ScriptDir & "\Test\" & $H_GetTextFiles[$I]) Next Link to comment Share on other sites More sharing options...
Dieuz Posted March 26, 2008 Author Share Posted March 26, 2008 Haha right! #Include <Misc.au3> #include <File.au3> $H_FolderPath = @SCRIPTDIR & "\test" $H_OutPutFilePath = @SCRIPTDIR & "\file.txt" Func _TextFileMerger($H_FolderPath, $H_OutPutFilePath, $V_ExecuteWhenDone = 0) $H_GetTextFiles = _FileListToArray($H_FolderPath, "*.txt") For $I = 1 To $H_GetTextFiles[0] $S_GetTextFileData = FileRead($H_FolderPath & "\" & $H_GetTextFiles[$I]) FileWrite($H_OutPutFilePath, " ***" & $H_GetTextFiles[$I] & "***" & @CRLF) FileWrite($H_OutPutFilePath, $S_GetTextFileData) FileWrite($H_OutPutFilePath, @CRLF & "***** Text File Divider *****" & @CRLF) Next If $V_ExecuteWhenDone = 1 Then ShellExecute($H_OutPutFilePath) EndFunc Cant get this to work properly, any idea? Link to comment Share on other sites More sharing options...
weaponx Posted March 26, 2008 Share Posted March 26, 2008 (edited) You could do this the old fashioned way using command line copy (see copy /?).Concatenation is performed when multiple source files are seperated with a plus symbol or you can use wildcards.Merge all txt files into output.txt:copy *.txt output.txtMerge only certain text files:copy text1.txt+text2.txt+text3.txt output.txtOf course you could easily generate a list of files to concatenate in AutoIt and use RunWait() to perform the copy. Edited March 26, 2008 by weaponx Link to comment Share on other sites More sharing options...
JustinReno Posted March 26, 2008 Share Posted March 26, 2008 (edited) #include <File.au3> _TextFileMerger(@ScriptDir & "\Test", @ScriptDir & "\All Files.txt") Func _TextFileMerger($H_FolderPath, $H_OutPutFilePath, $V_ExecuteWhenDone = 0) $H_GetTextFiles = _FileListToArray($H_FolderPath, "*.txt") For $I = 1 To $H_GetTextFiles[0] $S_GetTextFileData = FileRead($H_FolderPath & "\" & $H_GetTextFiles[$I]) FileWrite($H_OutPutFilePath, " ***" & $H_GetTextFiles[$I] & "***" & @CRLF) FileWrite($H_OutPutFilePath, $S_GetTextFileData) FileWrite($H_OutPutFilePath, @CRLF & "***** Text File Divider *****" & @CRLF) Next If $V_ExecuteWhenDone = 1 Then ShellExecute($H_OutPutFilePath) EndFunc Edited March 26, 2008 by Jardenix Link to comment Share on other sites More sharing options...
Dieuz Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks Jardenix, appreciate your help alot! Link to comment Share on other sites More sharing options...
JustinReno Posted March 26, 2008 Share Posted March 26, 2008 Your welcome, I'm also working on a _TextFileUnMerger(). 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