[英]How do I move variable named files from one directory to another?
Here is what I have so far that doesn't work: 这是我到目前为止无法正常工作的内容:
set from=V:\directory\CONCA*.*
set to=V:\directory\CONCA
for /f %%a IN ('dir "%from%" /b') do move %from%\%%a %to%
This returns the error message: 这将返回错误消息:
The filename, directory name, or volume label syntax is incorrect
文件名,目录名称或卷标签语法不正确
I do not always have a file in the directory that it is from, I do not want to see any error messages when it does not find a file. 我并不总是在它来自的目录中有一个文件,当它找不到文件时,我不想看到任何错误消息。
I do want to see what is it moving when it finds something to move. 我确实想看看当它找到要移动的东西时它在移动什么。
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%\"
)
Explanation: 说明:
2>NUL
redirect error messages to NUL ; 2>NUL
将错误消息重定向到NUL ; we need to escape >
redirection operator when used in a command processed by for /F
loop as 2^>NUL
; for /F
循环处理为2^>NUL
的命令中使用时,我们需要转义 >
重定向运算符; "delims="
to treat possible spaces in file names properly; "delims="
以正确处理文件名中的可能空格; /A:-D
exclude folders to prevent move "V:\\directory\\CONCA" "V:\\directory\\CONCA\\"
(attempt to move itself to itself ); /A:-D
排除文件夹以防止move "V:\\directory\\CONCA" "V:\\directory\\CONCA\\"
(尝试将自身移动到自身 ); echo "%from%\\%%a"
to satisfy I do want to see what is it moving when it finds something to move claim; echo "%from%\\%%a"
以满足我确实想查看它发现要移动的内容时发生了什么变化 ; rem move "%from%\\%%a" "%to%\\"
operational move
command is commented up using rem
merely for debugging phase: remove rem
as soon as debugged (but no sooner). rem move "%from%\\%%a" "%to%\\"
操作性move
命令仅在调试阶段使用rem
进行了注释:在调试后立即删除rem
(但不要尽快删除)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.