[英]How to move files from one directory to another but only move a file each time
[英]How do I move variable named files from one directory to another?
這是我到目前為止無法正常工作的內容:
set from=V:\directory\CONCA*.*
set to=V:\directory\CONCA
for /f %%a IN ('dir "%from%" /b') do move %from%\%%a %to%
這將返回錯誤消息:
文件名,目錄名稱或卷標簽語法不正確
我並不總是在它來自的目錄中有一個文件,當它找不到文件時,我不想看到任何錯誤消息。
我確實想看看當它找到要移動的東西時它在移動什么。
set "from=V:\directory"
set "to=V:\directory\CONCA"
rem ensure that target folder exists
md "%to%" 2>NUL
for /f "delims=" %%a IN ('dir "%from%\CONCA*.*" /b /A:-D 2^>NUL') do (
echo "%from%\%%a"
rem move "%from%\%%a" "%to%\"
)
說明:
2>NUL
將錯誤消息重定向到NUL ; 當在for /F
循環處理為2^>NUL
的命令中使用時,我們需要轉義 >
重定向運算符; "delims="
以正確處理文件名中的可能空格; /A:-D
排除文件夾以防止move "V:\\directory\\CONCA" "V:\\directory\\CONCA\\"
(嘗試將自身移動到自身 ); echo "%from%\\%%a"
以滿足我確實想查看它發現要移動的內容時發生了什么變化 ; rem move "%from%\\%%a" "%to%\\"
操作性move
命令僅在調試階段使用rem
進行了注釋:在調試后立即刪除rem
(但不要盡快刪除)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.