@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%" ) ) 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
时间: 2023-07-06 18:17:29 浏览: 86
assm.rar_Micro Mechanical_level set_level set模拟_水平集_水平集 三维
5星 · 资源好评率100%
好的,以下是针对你提供的批处理代码的优化方案:
```batch
@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=工艺文件
set skip_dirs=skip_dir1 skip_dir2 skip_dir3
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 (
set skip_file=0
for %%j in (%skip_dirs%) do (
echo "%%i" | findstr /i /c:"\\%%j\\" >nul && set skip_file=1
)
if not defined skip_file (
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%"
)
)
)
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
```
在这个优化方案中,我们添加了一个变量 `skip_dirs`,用来存储要跳过的文件夹名称。然后,在使用 `for /r` 遍历文件夹时,我们使用了一个内部的 `for` 循环和 `findstr` 命令来判断当前文件所在的文件夹是否包含在要跳过的文件夹列表中,如果是,则跳过当前文件。这样就可以实现指定跳过自定义的文件夹名称的功能了。
阅读全文