在目录中使用通配符从文件夹复制内容

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

每当我尝试 运行以上操作时,我都会收到以下错误:

The system cannot find the file specified. 0 file(s) copied.`

有人有什么建议吗?

使用 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"