[英]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. 我有一个excel文件,我每天从供应商FTP站点下载。 Every day the file name changes to contain the date and the vendor appends either "actual" or "estimate" to the end of the file.
每天文件名都会更改为包含日期,供应商会在文件末尾添加“actual”或“estimate”。
example: 例:
F_02262014_actual.xlsx F_02262014_actual.xlsx
F_02262014_estimate.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 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. 我的问题是,每当我在复制命令中使用通配符时,Windows都会假设我将多个文件附加到一个文件中。 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? 是否有命令或一系列命令将匹配文件模式的第一个文件复制到所需的文件名?
You cannot modify the behavior of the copy command in the way that you are asking for. 您无法以您要求的方式修改复制命令的行为。 Instead of doing a wildcard copy, try this:
不要做通配符拷贝,试试这个:
IF EXIST "\Source\F_02262014_actual.xlsx" (copy \Source\F_02262014_actual.xlsx \Target\CurrentFile.xlsx) ELSE (copy \Source\F_02262014_estimate.xlsx \Target\CurrentFile.xlsx)
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 %
如果这将从命令行执行,则将所有
%%
替换为%
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
我将
/b
开关添加到COPY
copy /B \Source\F_02262014* \Target\CurrentFile.xlsx
...worked for me! ......为我工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.