[英]Copy Contents From Folder Using Wildcard On The Directory
我有一个目录,其中包含需要移动到另一个目录的CSV文件:
C:\Users\JohnSmith\Desktop\Testing\report-20180819040000-20180826040000-4
我们每周都会收到一个新文件,其中目录名称中的日期将被更新。 我想创建一个批处理文件以在report*
上使用通配符复制此数据,但是我遇到了一些问题。
当我第一次导航到以下位置时,通配符似乎可以正常工作:
C:\Users\JohnSmith\Desktop\Testing\
然后使用:
dir report*
当我导航至时,它也可以正常工作
C:\Users\JohnSmith\Desktop\Testing\
然后跑
copy * C:\Users\JohnSmith\Desktop\Testing\Destination
我的目标是能够在我的批处理文件中运行一些简单的操作,如下所示:
copy C:\Users\JohnSmith\Desktop\Testing\report* C:\Users\JohnSmith\Desktop\Testing\Destination
每当我尝试运行以上命令时,都会出现以下错误:
该系统找不到指定的文件。 已复制0个文件。
有没有人有什么建议?
将For /D
与通配符一起用作目录名,然后也可以Copy
通配符与Copy
一起使用!
从命令提示符:
For /D %A In ("%UserProfile%\Desktop\Testing\report-*-*-*") Do @Copy "%A\*.csv" "%UserProfile%\Desktop\Testing\Destination">Nul 2>&1
从批处理文件:
@For /D %%A In ("%UserProfile%\Desktop\Testing\report-*-*-*") Do @Copy "%%A\*.csv" "%UserProfile%\Desktop\Testing\Destination">Nul 2>&1
或者,您可以直接在Powershell提示符下执行此操作:
Cp "$($Env:UserProfile)\Desktop\Testing\report-*-*-*\*.csv" "$($Env:UserProfile)\Desktop\Testing\Destination"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.