【解决方案】
test_1.bat 请参考Q-04把bat文件保存为ANSI编码:
https://mp.weixin.qq.com/s/Koje4FufWxWBs7ioDy_LJA- @echo off
- cd /d "%~dp0"
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('dir /b /ad *-* ^| findstr /v ".*-.*-"') do (
- echo 正在处理文件夹 %%a
- for /f "delims=" %%b in ('dir /b /ad "%%a"') do (
- echo 检查子文件夹 %%b
- set "AllN=0"
- set "FolderN=0"
- for /f "delims=" %%c in ('dir /b "%%a\%%b"') do (
- set /a "AllN+=1"
- )
- if !AllN! equ 0 (
- echo 情况[2] "%%a\%%b" 是空文件夹
- ) else (
- for /f "delims=" %%c in ('dir /b /ad "%%a\%%b"') do (
- set /a "FolderN+=1"
- )
- if !FolderN! neq 0 (
- echo 情况[3] "%%a\%%b" 两级子文件夹
- ) else (
- echo 情况[1] "%%a\%%b" 正常待移动的子文件夹
- )
- )
- if not exist "%~dp0%%b" (
- move "%%a\%%b" "%~dp0"
- ) else (
- echo 情况[4] 根目录存在同名文件夹 "%%b"
- )
- )
- )
- pause
复制代码
|