Jump to content
Sign in to follow this  

Utility to joint text files.

Recommended Posts

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.

;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)

    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
        ;The file the data will be written to.
        $Outfile = $CmdLine[$Count - 1]

    ;If old file is found delete it.
    If FileExists($Outfile) Then

    ;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)
                ;Get file contents
                $Buffer = GetFileData($CmdLine[$i])
                ;Append to the file
                FileWrite($fp, $Buffer)
                $Buffer = Null
    ;Close output file

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 by DreamVB

On Error Resume Pulling Hair Out.

Share this post

Link to post
Share on other sites

is there a way to use that to add headers like my code does.



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 by Werty

Some guy's script + some other guy's script = my script!

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...