微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

仅当内容保存在子目录中时才使用批处理移动内容,而不是根文件夹

如何解决仅当内容保存在子目录中时才使用批处理移动内容,而不是根文件夹

我正在尝试编写一个脚本,如果文件位于子文件夹(图像的 IE 日文件夹)中,而不是文件仅位于根目录中,则该脚本专门从源文件夹移动文件。子目录也需要移动。 到目前为止,我只有一个基本的 xcopy 脚本,但它也在复制没有文件夹的文件代码如下:

Set ImageDirectory=C:\Images
Set SMbrootAddress=<Server>
Set SMBImageDestinationFolder=Images

xcopy "%ImageDirectory%" "\\%sMbrootAddress%\%sMBImageDestinationFolder%" /d /i /s /y /r

解决方法

@ECHO OFF
SETLOCAL
rem The following settings for the source directory,destination directory,target directory,rem batch directory,filenames,output filename and temporary filename [if shown] are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files\t w o"
SET "destdir=u:\your results"

FOR /f "delims=" %%a IN (
 'dir /b /ad "%sourcedir%"'
 ) DO XCOPY /s /d /y "%sourcedir%\%%a" "%destdir%\%%a\" >nul
GOTO :eof

也就是说,只需在“本地根”目录下直接对所有必需的子目录名称执行目录扫描,然后xcopy找到找到的名称。我没有在测试中保留您的 xcopy 选项。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。