I have an excel file that I download from an vendor FTP site on a daily basis. Every day the file name changes to contain the date and the vendor appends either "actual" or "estimate" to the end of the file.
example:
F_02262014_actual.xlsx
F_02262014_estimate.xlsx
etc.
Because of these slight changes, I'm using a wildcard to copy the file to a consistent name in another directory.
Example:
copy \Source\F_02262014* \Target\CurrentFile.xlsx
My problem is that whenever I use a wildcard in the copy command, Windows assumes I'm appending several files to one. This causes the file to get corrupted (all contents deleted for some reason).
Is there a command, or series of commands, that will copy the first file matching the file pattern to the desired file name?
Switches are explained below. /XC − Prevents overwriting the files which have the same timestamp. /XN − Prevents overwriting of files with the newer timestamp than the source files. /XO − Prevents overwriting of files with the older timestamp than the source files.
As an alternative to entering a new name for each file, you can use a simple wildcard system to rename all copied or moved files at once. This is not a full pattern matching (or regular expressions) system; instead, the only wildcard character that's recognised is * (the asterisk).
When you have a number of files named in series (for example, chap1 to chap12) or filenames with common characters (like aegis, aeon, and aerie), you can use wildcards (also called metacharacters) to specify many files at once. These special characters are * (asterisk), ? (question mark), and [ ] (square brackets).
You can use the wildcard characters asterisk ( * ) and question mark ( ? ) as part of the file name argument. For example, part* loads the files part-0000 , part-0001 , and so on. If you specify only a folder name, COPY attempts to load all files in the folder.
I can't reproduce your reported problem.
DO you mean the source file is emptied, or that the target is empty?
I'd add the /b
switch to the COPY
copy /B \Source\F_02262014* \Target\CurrentFile.xlsx
...worked for me!
for %%f in ("\Source\F_02262014*") do copy /y "%%~ff" "\Target\CurrentFile.xlsx"
Written to include in batch file. If this will be executed from command line, replace all %%
with %
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With