我只是试图将d:\temp\test中的所有文件和子目录移动到d:\temp\archive,因此我尝试了以下命令:
move d:\temp\test\* d:\temp\archive\
move d:\temp\test\*.* d:\temp\archive\但我得到了这个错误的回报:
The filename, directory name, or volume label syntax is incorrect.然后我在网上翻来覆去,在一只蝙蝠里面试了一下:
for %%F in ( d:\temp\test\*.* ) do move /Y %%F d:\temp\archive这一次,它没有任何错误,但一切都是静止的,没有任何变化。
我在这里错过了什么?我正在Windows 10上试用这个。
发布于 2017-06-05 09:23:44
好的,如果您只想从\test\中移动所有文件目录,那么这将首先执行文件,然后是批处理中的目录。for /d将复制目录、子目录和文件。
@echo off
move "d:\temp\test\*" "d:\temp\archive"
for /d %%a in ("D:\temp\test\*") do move "%%~fa" "d:\temp\archive\"另外,在cmd以下运行时,会出现一个错误。
move d:\temp\test\* d:\temp\archive这是因为它将移动所有文件,而不是目录。如果获得The filename, directory name, or volume label syntax is incorrect.,则没有文件,只有移动命令看不到的文件夹。
注意:从批处理文件中删除,/Y开关被禁用,如果存在文件夹,则不会替换文件夹。因此,如果您经常计划覆盖,也许应该使用xcopy和update存档,那么在成功复制文件之后,在d:\temp中运行一个delete。
最后,始终将路径括在双"中。在本例中,如果没有双引号,它会很好地工作,但是如果您有类似于move d:\program files\temp\* d:\temp\archives的内容,它将创建一个错误,因为程序和文件之间有空格,所以使用move "d:\program files\temp\*" "d:\temp\archive总是更好。
编辑理解%%~分配。在这些示例中,我们使用%%I而不是%%a
%~I : expands %I removing any surrounding quotes (")
%~fI : expands %I to a fully qualified path name
%~dI : expands %I to a drive letter only
%~pI : expands %I to a path only
%~nI : expands %I to a file name only
%~xI : expands %I to a file extension only
%~sI : expanded path contains short names only
%~aI : expands %I to file attributes of file
%~tI : expands %I to date/time of file
%~zI : expands %I to size of file
%~$PATH:I : searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
if the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI : expands %I to a drive letter and path only
%~nxI : expands %I to a file name and extension only
%~fsI : expands %I to a full path name with short names only
%~dp$PATH:I : searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI : expands %I to a DIR like output line`https://stackoverflow.com/questions/44363472
复制相似问题