Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy a file using a wildcard in Windows without appending?

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?

like image 944
FistOfFury Avatar asked Feb 26 '14 17:02

FistOfFury


People also ask

How can I copy files without overwriting in Windows?

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.

Which wildcard is used for copying all 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).

How do you use a wildcard in a filename?

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).

How do you copy a wildcard character in command?

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.


2 Answers

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!

like image 162
Magoo Avatar answered Oct 22 '22 10:10

Magoo


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 %

like image 25
MC ND Avatar answered Oct 22 '22 09:10

MC ND