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