DreamVB Posted September 15, 2014 Posted September 15, 2014 (edited) This is a small program I made to join text files, I am one of them people that has text files here and there on the desktop, but after a while you end of deleteing them cos your desktop is a mess, so I made this to allow me to join them into one big file. it has the option to also add option header, Well here is the code hope you find it usfull. expandcollapse popup;Ben's Text fILE jOINTER #include <FileConstants.au3> #include <String.au3> Local $Buffer Local $Filename Local $LineSep Local $Outfile Local $Count Local $AddSep = False Local $Parm Local $fp Local $i Func GetFileData($Filename) Local $fp Local $data If FileExists($Filename) Then $fp = FileOpen($Filename, 0) $data = FileRead($fp) FileClose($fp) EndIf Return $data ;Clear up $data = Null EndFunc ;==>GetFileData ;Get command line count. $Count = UBound($CmdLine) ;Filename seperaor line $LineSep = _StringRepeat("-", 69) ;Check parm count If ($Count > 1) Then ;Check if we are adding file seperator. $AddSep = StringUpper($CmdLine[1]) = "-H" ;Check for out file parm $Parm = StringUpper($CmdLine[$Count - 2]) ;Check for -O out file parm. If ($Parm <> "-O") Then Exit Else ;The file the data will be written to. $Outfile = $CmdLine[$Count - 1] EndIf ;If old file is found delete it. If FileExists($Outfile) Then FileDelete($Outfile) EndIf ;Open output file $fp = FileOpen($Outfile, $FO_APPEND) For $i = 1 To $Count - 2 $parm = StringUpper($CmdLine[$i]) If ($parm <> "-H") And ($parm <> "-O") Then ;Get filename $Filename = $CmdLine[$i] If FileExists($Filename) Then If ($AddSep = True) Then ;Add sep FileWrite($fp, $LineSep & @CRLF) ;Add filename FileWrite($fp, $Filename & @CRLF) ;Add seperator string FileWrite($fp, $LineSep & @CRLF) EndIf ;Get file contents $Buffer = GetFileData($CmdLine[$i]) ;Append to the file FileWrite($fp, $Buffer) $Buffer = Null EndIf EndIf Next ;Close output file FileClose($fp) EndIf Example to join files with header. JoinText.exe -h "c:\out\test.ini" "c:\out\test.txt" "C:\out\tasks.txt" -o "join.txt" To joing without header just remove the -h Edited September 15, 2014 by DreamVB On Error Resume Pulling Hair Out.
Werty Posted September 16, 2014 Posted September 16, 2014 Run(@ComSpec & " /c copy /b *.txt all.txt") DreamVB 1 Some guy's script + some other guy's script = my script!
DreamVB Posted September 16, 2014 Author Posted September 16, 2014 On 9/16/2014 at 10:55 AM, Werty said: Run(@ComSpec & " /c copy /b *.txt all.txt") Thanks usfull tip to remmber, but also is there a way to use that to add headers like my code does. On Error Resume Pulling Hair Out.
Werty Posted September 16, 2014 Posted September 16, 2014 (edited) On 9/16/2014 at 11:12 AM, DreamVB said: is there a way to use that to add headers like my code does. Yes...RunWait(@ComSpec & " /c for %I in (*.txt) do @echo %~nxI >>all.txt >>all.txt && @echo %~tI >>all.txt && type ""%~nxI"" >>all.txt && @echo. >>all.txt && @echo. >>all.txt") Edited September 16, 2014 by Werty Some guy's script + some other guy's script = my script!
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