简体   繁体   English

如何在Windows中使用通配符复制文件而不附加?

[英]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.

相关问题 如何使用Java将文件从一台Windows计算机复制到另一台Windows计算机文件夹 - How do i copy a file from one windows machine to other windows machine folder using java 不使用 windows 文件缓存复制文件 - Copy a file without using the windows file cache 如何在没有CopyFile或CopyFileEx的情况下在Windows上复制大文件? - How can I copy a large file on Windows without CopyFile or CopyFileEx? 如何使用 C++ 在 Windows 中复制和粘贴文件? - How can I copy and paste a file in Windows using C++? 如何使用 windows 命令行下载文件而无需输入代理密码? - How do I download a file using windows command line without having to input a proxy password? 如何在不阻止Windows的情况下打开文件? - How do I open a file without blocking in windows? 如何使用 COPY 命令将 append 复制到文件 - How do I append to a file using the COPY command 使用通配符进行复制 - Using a wildcard to copy 如何编写Windows批处理脚本,将最新文件从目录复制到新文件夹? - How do I write a Windows batch script to copy the newest file from a directory into new folder? 如何从Windows批处理文件的递归副本中排除特定目录? - How do I exclude specific directories from a recursive copy in a Windows batch file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM