简单的Windows批处理移动文件夹

ioojimooi

我只是想移动的所有文件和子目录d:\temp\testd:\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.

然后,我在网上进行了挖掘,并在doc bat中尝试了此操作:

for %%F in ( d:\temp\test\*.* ) do move /Y %%F d:\temp\archive

这次它没有显示任何错误,但是一切都停滞不前,没有进行任何更改。

我在这里想念什么?我正在Windows 10上尝试此操作。

格哈德

好的,如果您只想从\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.没有,则没有文件,只有move命令看不到的文件夹。

注意从批处理文件中,将/Y禁用开关,并且如果存在文件夹,则不会替换文件夹。因此,如果您打算经常进行覆盖,或者改而使用xcopy和更新存档,则在d:\temp成功复制文件立即运行删除操作

最后,始终将路径包含在double中"在这种情况下,不用双引号就可以正常工作,但是如果您有类似的东西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`

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 Windows 批处理脚本将多个文件从子文件夹移动到单个文件夹

Windows批处理脚本,以某种平衡的方式将XML文件移动到多个文件夹

使用批处理移动文件并浏览子文件夹

整理文件夹的简单批处理脚本

批处理脚本:根据源文件夹名称将文件移动到文件夹

Windows批处理文件,用于根据文件名将文件移动到子文件夹

Windows批处理-根据文件名和扩展名将文件移动到文件夹

递归地将文件夹名称附加到其中的文件并将所有文件移动到基本文件夹 Windows 批处理文件

简单的Windows批处理文件,它将文件复制到文件夹,并创建带有时间戳的子文件夹

Windows批处理命令仅删除文件夹

Windows 批处理覆盖文件夹和子文件夹中的现有文件

批处理文件,用于根据文件名将文件移动到文件夹

Windows批处理-匹配文件夹名称中带有点(。)的文件夹

使用CMD或批处理将多个文件从子文件夹移动到一个文件夹

批处理脚本将每组 n 个文件移动到不同的新文件夹

批处理脚本将x个文件移动到空文件夹

一个批处理文件首先移动最近的文件夹?

批处理文件以将文件夹移动到另一个

批处理-将以模式开头的文件移动到某个文件夹

尝试移动时批处理文件无法访问文件夹

批处理文件在对称文件夹结构之间移动

批处理编程:基于修改的日期将文件移动到文件夹

如何使用批处理文件中的目录通配符移动或复制文件夹?

使用部分名称创建文件夹和移动文件的批处理脚本

批处理命令根据文件名创建文件夹并将文件/文件夹移动到创建的文件夹

查找批处理文件夹

批处理文件中获取Windows Download文件夹的路径(Download shell文件夹)

Windows批处理文件:转换子文件夹中的所有文件

删除Windows批处理脚本中除一个文件夹之外的文件夹?