Merge files
In the old dos days you could combine 2 files as save to a third file:
copy file1 + file2 file3
It still works in a dos shell.
I did this:
Shell("copy " & file1 & " + " & file2 & " " & file3)
I got an error that file3 cannot be found. I know it doesn't exist I want to create it. So I created a bat file:
copy %1 + %2 %3
and called it as such:
Shell("ccopy " & file1 & " " & file2 & " " & file3)
I still get the error that file3 cannot be found.
First I don't see how it can tell from the shell that file3 is a file.
How do I do this otherwise?
Do I have to create a blank file before calling it?
It was not finding the ccopy.bat without the full path. Solves the file not found.
However, it will only copy the first file to the third file using either of the two shell commands. In dos the copy copies file1 and file2 to file3. In the shell command it doesn't.
Here's the reason:
The copy command is an internal DOS command and can't be directly executed because there's no file named copy.exe or copy.com...
Call Shell("cmd /c Copy " & file1 & " + " & file2 & " " & file3,vbHide)
this will work for Windows Xp and copies the two files.
Note that: Command copies only the first file and doesn't copy the others , really i don't know why but cmd.exe does the whole task.
the argument /c executes a Dos Internal Command then terminates.
To know more about copy just open cmd.exe then type copy /?
Best regards,
Amr Ouf
You'll need to read both files in, combine them, and then write them back. An example might be:
Private Sub MergeFiles(ByVal file1 As String, ByVal file2 As String, ByVal outputfile As String)
FileIO.FileSystem.WriteAllText(outputfile, FileIO.FileSystem.ReadAllText(file1), True)
FileIO.FileSystem.WriteAllText(outputfile, FileIO.FileSystem.ReadAllText(file2), True)
End Sub
I think to use a .NET code is better than using shell command, because this wouldn't work in windows 98 as there's no cmd.exe!!!!
I think if you use a code like that whar rkimble written but in a binary format will be better.
The above function is more flexible and relibale.
Using external command to run is an operating system dependant and there's no guarantee for the file is generated or written successfull, so i recommend to use this funciton instead.