How do I get cmd to ‘combine’ multiple files from a windows backup? - batch-file

I am trying to extract a .pst file from a windows backup. In order to do this I need to copy each ‘partial’ file from the backup zips and then combine them together to make the one file. I have a command that will copy them out and combine them from this post but the problem I have is that cmd is not doing it in numerical order, therefore the file is not complete. I am using this script to put the files in order:
Echo y | for /F "tokens=*" %A in (filenamesinorder.txt) do copy /b %A “c:\pstcombiner\combined.pst”
But all this does is copy each individual file and overwrites it. I get that that’s what the command does but I need it to combine all the files into one. What am I doing wrong?

Form the Microsoft documentation for the copy command:
To append files, specify a single file for destination, but multiple files for source (use wildcard characters or file1+file2+file3 format).
You’ll need to construct the source text for the copy in your for loop and do the copy after; I’ll see if I can provide an example when I am at my Windows system.

Instead of concatenating, you could try merging using the type command:
create an empty target file
copy nul target.ext > nul
then loop the type command to merge the files to the end of the target file
type fileN.ext>>target.ext
where fileN.ext is file 1, 2,3 ... n

Related

Using cmd to move files with a specific filename mask

I am trying to use a simple windows cmd command to move a set of .csv files from one directory to another.
I know that this can be easily achieved through:
MOVE "*.csv" "D:/lorik_home"
The issue comes when I want to only move some specific files with a filename mask, for instance, I want to move all files which are in the .csv extension and start with the name: lorik_files_. I already tried using:
MOVE "lorik_files_*.csv" "D:/lorik_home"
This works when there is only one file of the format: lorik_files_20112233_09_33_33.csv, but when there are two files with the masks such as:
lorik_files_20112233_09_33_33.csv
lorik_files_20112233_10_23_42.csv
I get an error such as:
A duplicate file name exists, or the file cannot be found.
I need a hand for capturing those filename prefix masks, conditioned by .csv extension at the end.

Batch file to copy multiple files by using partial filename

I want to copy multiple files from source to destination and the first 8 letters of the files are same so by using this partial file name i would like to copy and content of the files also should be replaced with string while copying.
for example:
I have three file in source path and those are like below
samefile123.txt
samefile456.txt
myfile.txt
ratefile.txt
I want to pick up the first two files because the first 8 letters of the files are same and if the files have content like apple or banana or grape words those words should be replace with papaya.
To copy multiple text files with the same name using batch you need to use a wildcard. Here is what I have tested on my computer and it works.
xcopy "C:\%username%\desktop\test\samefi*.txt" "C:\users\%username%\desktop"
For more information on the uses of xcopy use:
xcopy /?
You can read more on wildcards here.
If I could get more information on the second part about changing the name from grape to papaya I may assist with that.

How do you automatically select F in batch file?

In a batch file if I have for example
%backupcmd% "Desktop\testfile" "%drive%\grab\test" it pops up with http://prntscr.com/clbmen, how would I designate it in my batch to automatically select F?
You are probably asking about automatically sending F to the command as it presents a query to which you need to reply F for File, not Directory.
The classic method is
echo F|yourcommand....
Here is a different approach (there is actually no need to pipe characters into commands)...
For copying a single file, use copy rather than xcopy, because copy assumes the target to be a file in such situations:
copy "\path\to\a\singe\source\file.txt" "\path\to\destination\file.txt"
For multiple source files, xcopy is better as it features a /I switch -- see xcopy /?.

How to create many copies of a single file with different names using command prompt?

I need to create new copies of a single .html file. The file's name is 065.html.
I copied the file into 066.html using the following command:
C:\>copy 065.html 066.html
But I need more. I need to copy up to 090.html
How can I do this? A loop should do this but I don't know the syntax.
I have tried to use the command as shown here,
for /L %%i IN (66,1,90) do copy 065.html 0%%i.html
but I get an error message that says
%%i was unexpected at this time
I have deleted one preceding % signs. It works now.
for /L %i IN (66,1,90) do copy 065.html 0%i.html

Copy and rename XLSX file using batch script

I have many XLSX files that I will need to copy to a new location and rename. The Excel files appear to be copied to the new location, but when I open them, I keep getting the "found unreadable content" error message, and all the data is gone.
I use an asterisk to find the file, and then I want to rename it so that it doesn't have the date string.
This is the code I'm using:
set OrigLocn=C:\OldLocation\
set NewLocn=C:\NewLocation\
copy "%OrigLocn%S5820-003-terms-sg*" "%NewLocn%S5820-003-terms-sg.xlsx"
copy "%OrigLocn%S5921-293-terms-addp*" "%NewLocn%S5921-293-terms-addp.xlsx"
copy "%OrigLocn%S5921-293-terms-sg*" "%NewLocn%S5921-293-terms-sg.xlsx"
copy "%OrigLocn%S5921-349-terms-addp*" "%NewLocn%S5921-349-terms-addp.xlsx"
I would use the xcopy command to copy over multiple files then use REN to change the name.
XCOPY: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
REN: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
change copy to copy /b. This copies in binary mode but the default is ascii mode which terminates the copy when certain binary sequences are encountered.
Using the wildcard in the copy command will cause the target file to be concatenated if more than one file matches the filespec.
if this is the case then you'll need different code to remove the date string.

Resources