Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative to DOS copy command 1

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Joined
Mar 23, 2000
Messages
3,392
Location
GB
Hi

I need to implement the equivalent of the the DOS copy command to combine one or more files together such as :-

RUN C:\temp\test1.txt + C:\temp\test2.txt C:\temp\test3.txt

The DOS window can be hidden with a suitable WinAPI call.

Anyone got any WSH or WinAPI calls to achieve the same result? HTH

Chris [pc2]
 
Chris

FILETOSTR( ) function might help.

myChar=FILETOSTR("c:\test1.txt") && Copies to content of text1 to a string
strtofile(myChar,"c:\test2.txt",1) && copies the string and appends text2 (0=replace,1=appends)
Mike Gagnon
 
Thanks Mike

The example I used was not very helpful - there may be n files to combine, so whilst your example is fine for appending one at a time it might be slower than the equivalent DOS command combining n files in one hit.

A drawback of the DOS command will be the 128 character limit for a command line.

With the length of some Windows path\filenames, that will rearing its ugly head pretty soon. HTH

Chris [pc2]
 
After perusing the MSDN a little, it looks like the Windows API CopyFile etc functions don't have any sort of append option. Only overwrite and fail if the source file exists. I agree with Mike too, I think you may be best off using the FILETOSTR() and STRTOFILE() functions also:

USE MyFileTable
SCAN
STORE MyFileTable.SomeFileField TO cSource
IF FILE(cSource)
cWorkString = FILETOSTR(cSource)
STRTOFILE(cWorkString, 'OutFile.TXT', .T.)
ENDIF
ENDSCAN

Note that the lAdditive parameter for STRTOFILE() is logical though, not numeric.
Dave S.
 
Dave

It can be numeric with VFP 7.0

0 (default) The file is overwritten with the character string (formerly lAdditive=.f.)

1 The string is appended to the end of the file (formerly lAdditive=.t.).

2 Write Unicode Byte Order Mark (BOM) FF FE at the beginning of file. cExpression is assumed to be UNICODE, therefore no translation is performed. The file is overwritten

4 Write UTF-8 Byte Order Mark (BOM) EF BB BF at the beginning of file. cExpression is assumed to be UTF-8, therefore no translation is performed. The file is overwritten. HTH

Chris [pc2]
 
Hmm. I am still using VFP 6. A numeric value causes an error.
Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top