[英]Copy Contents From Folder Using Wildcard On The Directory
I have a directory which contains CSV files needing to be moved to another directory: 我有一个目录,其中包含需要移动到另一个目录的CSV文件:
C:\Users\JohnSmith\Desktop\Testing\report-20180819040000-20180826040000-4
We receive a new file weekly where the dates in the directory name will be updated. 我们每周都会收到一个新文件,其中目录名称中的日期将被更新。 I want to create a batch file to copy this data using a wildcard on
report*
but I am running into some issues. 我想创建一个批处理文件以在
report*
上使用通配符复制此数据,但是我遇到了一些问题。
The wildcard appears to work without any issues when I first navigate to: 当我第一次导航到以下位置时,通配符似乎可以正常工作:
C:\Users\JohnSmith\Desktop\Testing\
then use: 然后使用:
dir report*
It also works fine when I navigate to: 当我导航至时,它也可以正常工作
C:\Users\JohnSmith\Desktop\Testing\
then run 然后跑
copy * C:\Users\JohnSmith\Desktop\Testing\Destination
My goal is to be able to run something simple in my batch file like the below: 我的目标是能够在我的批处理文件中运行一些简单的操作,如下所示:
copy C:\Users\JohnSmith\Desktop\Testing\report* C:\Users\JohnSmith\Desktop\Testing\Destination
Whenever I try running the above, I receive the following error: 每当我尝试运行以上命令时,都会出现以下错误:
The system cannot find the file specified.
该系统找不到指定的文件。 0 file(s) copied.`
已复制0个文件。
Does anyone have any suggestions? 有没有人有什么建议?
Use For /D
with a wildcards for your directory name, then you can use Copy
with a wildcard too! 将
For /D
与通配符一起用作目录名,然后也可以Copy
通配符与Copy
一起使用!
From the Command Prompt: 从命令提示符:
For /D %A In ("%UserProfile%\Desktop\Testing\report-*-*-*") Do @Copy "%A\*.csv" "%UserProfile%\Desktop\Testing\Destination">Nul 2>&1
From a batch file: 从批处理文件:
@For /D %%A In ("%UserProfile%\Desktop\Testing\report-*-*-*") Do @Copy "%%A\*.csv" "%UserProfile%\Desktop\Testing\Destination">Nul 2>&1
Alternatively you could do it directly at the Powershell Prompt: 或者,您可以直接在Powershell提示符下执行此操作:
Cp "$($Env:UserProfile)\Desktop\Testing\report-*-*-*\*.csv" "$($Env:UserProfile)\Desktop\Testing\Destination"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.