我有一个目录,其中包含需要移动到另一个目录的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
!
从命令提示符:
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"