缘起:网上下载了一份源代码,但是由于其中的存在某些空文件夹,而且文件夹特别多,且目录也比较深,所以写一个批处理,用来查找出这份源代码中的空文件夹,使其可以在github上提交
1 @echo off 2 cls 3 rem --- main program --- 4 set baseDir=C:\Users\Desktop\src\src\com\sourcecode 5 6 echo --- callBefore --- 7 call :subPro 8 echo --- callAfter --- 9 10 goto mainEnd 11 rem --- main program --- 12 13 14 rem sub program 15 :subPro 16 call :subPath %baseDir% 17 goto :eof 18 19 rem sub 拼接新的路径 20 rem %1 当前查找路径 21 :subPath 22 rem 判断当前文件夹下面是否有文件存在 23 set fileCount=0 24 for /F "delims=" %%c in (‘dir /B %1‘) do set /a fileCount+=1 25 if %fileCount% == 0 echo %1 26 27 rem 递归调用 28 for /F "delims=" %%d in (‘dir /B/A:d %1‘) do call :subPath %1\%%d 29 30 goto :eof 31 32 33 :subDeep 34 set fileName=%1 35 echo %fileName% 36 37 rem program end point, SHOULDN‘T WRITE ANY CODE IN HERE 38 :mainEnd
上面批处理的第25行将空文件夹的路径打印出来,如果要向改文件夹中复制文件,则使用下面的代码替换25行即可
1 set emptyFile=C:\Users\blaze\Desktop\bat\.gitkeep 2 if %fileCount% == 0 copy "%emptyFile%" %1
时间: 2024-10-12 21:14:28