Jump to content

Append TXT files in one


Recommended Posts

Hi,

Sorry for a newbies question.

How to append a series of text files in one all together. i had tried "FileCopy" with source "work*.txt", but it copied the first file only!!!??

work1.txt + work2.txt + work3.txt .... > all.txt

Thanks in advance.

Link to comment
Share on other sites

HI,

quick try.

$File1 = "Example.log"; Saved in UNICODE
$File2 = "Example.txt"; Saved in ASNI

Run(@ComSpec & ' /c Type "' & $File1 & '" > "' & $File2 & '"',"",@SW_HIDE)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

With any command line utility, the first thing to try is running the command with /? or /h or -? or -h or ? or h.

Like this:

C:\>copy /?

Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]

[+ source [/A | /B] [+ ...]] [destination [/A | /B]]

source Specifies the file or files to be copied.

/A Indicates an ASCII text file.

/B Indicates a binary file.

/D Allow the destination file to be created decrypted

destination Specifies the directory and/or filename for the new file(s).

/V Verifies that new files are written correctly.

/N Uses short filename, if available, when copying a file with a

non-8dot3 name.

/Y Suppresses prompting to confirm you want to overwrite an

existing destination file.

/-Y Causes prompting to confirm you want to overwrite an

existing destination file.

/Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.

This may be overridden with /-Y on the command line. Default is

to prompt on overwrites unless COPY command is being executed from

within a batch script.

To append files, specify a single file for destination, but multiple files

for source (using wildcards or file1+file2+file3 format).

Note the last two lines!

If any of the file paths contain spaces, you need to enclose the entire path with quotes:

copy "file 1"+c:\file2+"c:\program files\file3" "destination file"

Note that c:\file2 doesn't need quotes, but the other two files specified do.

If you encounter problems like files are being truncated, you may have control characters within the file that don't belong there. A [Control]Z embedded in the middle of a text file will terminate the copy operation for that file wherever it is located - even if it's in the middle of the file (which it shouldn't be but...). To avoid that problem, use the /B (binary) switch which forces the copy operation to copy the entire file based on size rather than content like this:

copy /B "file 1"+c:\file2+"c:\program files\file3" "destination file"

Hope this helps.
Link to comment
Share on other sites

Or we can go with the AutoIt solution... not really sure which would be faster in your case, but here we are.

Dim $fileAll
Dim $lastFile

$lastFile = 10  ;This is the number that is on the last file. Ex.
                ;You have work1.txt thru work11.txt then $lastFile
                ;should be 11.

$fileAll = FileOpen("all.txt", 1) ;Write mode = Append to end of file.

For $i = 1 To $lastFile Step 1
    FileWrite($fileAll, FileRead("work" & $i & ".txt"))
Next

FileClose($fileAll)

I hope it helps,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

HI,

this should work also, although it might be a bit slow. :P

#include<Array.au3>
#include<file.au3>

$pathFile1 = '1.txt'
$pathFile2 = '2.txt'
$pathGoal = '3.txt'

Dim $a
If Not _FileReadToArray($pathFile1 ,$a) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

Dim $b
If Not _FileReadToArray($pathFile2 ,$B) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

_FileWriteFromArray('3.txt' ,arrayConcatenate($a, $b, 1, 1),1)

Func arrayConcatenate($array1, $array2, $indexA=0, $indexB=0)
    Local $a[UBound($array1) + UBound($array2) ]
    Local $k
    For $i = $indexA To UBound($array1) - 1
        $a[$i] = $array1[$i]
        $k += 1
    Next
    For $i = $indexB To UBound($array2) - 1
        $a[$i + $k] = $array2[$i]
    Next
    Return $a
EndFunc   ;==>arrayConcatenate

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks EVERYONE, especially JS.

FileRead & FileWrite solution did the job very well. it took only a few seconds to went thru 7-8MB data.

Jasonz

Glad I could be of assistance.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...