修改代码实现跳过搜索名称为未分配的文件夹功能
时间: 2024-02-27 20:52:18 浏览: 16
好的,可以在 `for` 循环内部添加一个条件判断,判断当前遍历到的文件夹名称是否为“未分配”,如果是,则跳过该文件夹,继续遍历下一个文件夹。
修改后的代码如下所示:
```
@echo off
set current_path=%cd%
set file_type1=.prt
set file_type2=.cxp
set file_type3=.doc
set folder_name1=程序模型
set folder_name2=工艺规程
set folder_name3=沟通记录
set destination_folder=工艺文件
if not exist "%folder_name1%" mkdir "%folder_name1%"
if not exist "%folder_name2%" mkdir "%folder_name2%"
if not exist "%folder_name3%" mkdir "%folder_name3%"
for /r "%current_path%" %%i in (*) do (
if "%%~xi" == "%file_type1%" (
copy "%%i" "%folder_name1%"
) else if "%%~xi" == "%file_type2%" (
copy "%%i" "%folder_name2%"
) else if "%%~xi" == "%file_type3%" (
copy "%%i" "%folder_name3%"
) else if "%%~ni" == "未分配" (
rem 如果文件夹名称为“未分配”,则跳过该文件夹,继续遍历下一个文件夹
echo Skipping folder "%%~dpi%%~ni"
)
)
xcopy "%folder_name1%" "%destination_folder%%folder_name1%" /s /e
rd "%folder_name1%" /s /q
xcopy "%folder_name2%" "%destination_folder%%folder_name2%" /s /e
rd "%folder_name2%" /s /q
xcopy "%folder_name3%" "%destination_folder%%folder_name3%" /s /e
rd "%folder_name3%" /s /q
```
如上所示,我们添加了一个 `else if` 分支,判断当前文件夹名称是否为“未分配”,如果是,则通过 `echo` 命令输出一条提示信息,并跳过该文件夹,继续遍历下一个文件夹。
希望对您有所帮助!