标题: [文件操作] 【分享】批处理按年份和十二生肖归类文件 [打印本页]
作者: zhengzhenhui 时间: 2024-7-26 15:42 标题: 【分享】批处理按年份和十二生肖归类文件
十二生肖- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
-
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- if "%%b" leq "01" (
- call :1 "%%a年\1-子鼠" "%%i"
- )
- if "%%b" leq "02" (
- call :1 "%%a年\2-丑牛" "%%i"
- )
- if "%%b" leq "03" (
- call :1 "%%a年\3-寅虎" "%%i"
- )
- if "%%b" leq "04" (
- call :1 "%%a年\4-卯兔" "%%i"
- )
- if "%%b" leq "05" (
- call :1 "%%a年\5-辰龙" "%%i"
- )
- if "%%b" leq "06" (
- call :1 "%%a年\6-巳蛇" "%%i"
- )
- if "%%b" leq "07" (
- call :1 "%%a年\7-午马" "%%i"
- )
- if "%%b" leq "08" (
- call :1 "%%a年\8-未羊" "%%i"
- )
- if "%%b" leq "09" (
- call :1 "%%a年\9-申猴" "%%i"
- )
- if "%%b" leq "10" (
- call :1 "%%a年\10-酉鸡" "%%i"
- )
- if "%%b" leq "11" (
- call :1 "%%a年\11-戌狗" "%%i"
- )
- if "%%b" leq "12" (
- call :1 "%%a年\12-亥猪" "%%i"
- )
- endlocal
- )
- )
-
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
-
- exit
复制代码
十二星座- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
-
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- if "%%b" leq "01" (
- call :1 "%%a 年\1-白羊座" "%%i"
- )
- if "%%b" leq "02" (
- call :1 "%%a 年\2-金牛座" "%%i"
- )
- if "%%b" leq "03" (
- call :1 "%%a 年\3-双子座" "%%i"
- )
- if "%%b" leq "04" (
- call :1 "%%a 年\4-巨蟹座" "%%i"
- )
- if "%%b" leq "05" (
- call :1 "%%a 年\5-狮子座" "%%i"
- )
- if "%%b" leq "06" (
- call :1 "%%a 年\6-处女座" "%%i"
- )
- if "%%b" leq "07" (
- call :1 "%%a 年\7-天秤座" "%%i"
- )
- if "%%b" leq "08" (
- call :1 "%%a 年\8-天蝎座" "%%i"
- )
- if "%%b" leq "09" (
- call :1 "%%a 年\9-射手座" "%%i"
- )
- if "%%b" leq "10" (
- call :1 "%%a 年\10-摩羯座" "%%i"
- )
- if "%%b" leq "11" (
- call :1 "%%a 年\11-水瓶座" "%%i"
- )
- if "%%b" leq "12" (
- call :1 "%%a 年\12-双鱼座" "%%i"
- )
- endlocal
- )
- )
-
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
-
- exit
复制代码
社会主义核心价值观【有个字论坛不让写请自己改写】- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
-
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- if "%%b" leq "01" (
- call :1 "%%a年\1-富强" "%%i"
- )
- if "%%b" leq "02" (
- call :1 "%%a年\2-**" "%%i"
- )
- if "%%b" leq "03" (
- call :1 "%%a年\3-文明" "%%i"
- )
- if "%%b" leq "04" (
- call :1 "%%a年\4-和谐" "%%i"
- )
- if "%%b" leq "05" (
- call :1 "%%a年\5-自由" "%%i"
- )
- if "%%b" leq "06" (
- call :1 "%%a年\6-平等" "%%i"
- )
- if "%%b" leq "07" (
- call :1 "%%a年\7-公正" "%%i"
- )
- if "%%b" leq "08" (
- call :1 "%%a年\8-法治" "%%i"
- )
- if "%%b" leq "09" (
- call :1 "%%a年\9-爱国" "%%i"
- )
- if "%%b" leq "10" (
- call :1 "%%a年\10-敬业" "%%i"
- )
- if "%%b" leq "11" (
- call :1 "%%a年\11-诚信" "%%i"
- )
- if "%%b" leq "12" (
- call :1 "%%a年\12-友善" "%%i"
- )
- endlocal
- )
- )
-
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
-
- exit
复制代码
作者: zhengzhenhui 时间: 2024-7-26 15:47
按年份和月份- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
-
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- set "month=%%b"
- call :1 "%%a\%%b 月" "%%i"
- endlocal
- )
- )
-
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
- pause
- exit
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
复制代码
按年份+上半年和下半年- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- if "%%b" leq "06" (
- call :1 "%%a\上半年" "%%i"
- ) else (
- call :1 "%%a\下半年" "%%i"
- )
- endlocal
- )
- )
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
- pause
- exit
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
复制代码
按 年份+上下学期- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- if "%%b" leq "06" (
- call :1 "%%a\上学期" "%%i"
- ) else (
- call :1 "%%a\下学期" "%%i"
- )
- endlocal
- )
- )
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
- pause
- exit
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
复制代码
作者: 77七 时间: 2024-7-26 20:10
多个if可以这样写,提高效率。(我刚来论坛接触bat时,还是站长教我的)- if "%%b" equ "01" (
- call :1 "%%a 年\1-白羊座" "%%i"
- ) else if "%%b" equ "02" (
- call :1 "%%a 年\2-金牛座" "%%i"
- )
复制代码
给一个模板,可以在6-8行自行定义。
- @echo off
- cd /d "%~dp0"
- set "dp=%~dp0"
- set "dp=%dp:\=\\%"
- set n=1
- for %%a in ("01=白羊座" "02=金牛座" "03=双子座" "04=巨蟹座" "05=狮子座" "06=处女座" "07=天秤座" "08=天蝎座" "09=射手座" "10=摩羯座" "11=水瓶座" "12=双鱼座") do (
- set _%%~a
- )
- for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~f0" ^|findstr /rvibc:\\"%dp%[1-2][0-9][0-9][0-9]\\\\"') do (
- for /f "tokens=1-2 delims=/" %%a in ("%%~ti") do (
- setlocal
- for /f "tokens=2 delims==" %%x in ('set _ ^|findstr "%%b"') do (
- call :1 "%%a\%%x" "%%i"
- )
- endlocal
- )
- )
- for /f "delims=" %%i in ('dir /b /s /ad ^|sort /r') do (
- rd "%%i" 2>nul
- )
- pause
- exit
-
- :1
- md "%~1" 2>nul
- if not exist "%~1\%~n2%m%%~x2" (
- move "%~2" "%~1\%~n2%m%%~x2"
- exit /b
- )
- set /a n+=1
- set m=_%n%
- goto :1
复制代码
作者: zhengzhenhui 时间: 2024-7-26 22:36
回复 3# 77七
学到了,里面的子程序那个妙,多个if的应用,整体极限亚索啊,相比我写的屎山代码,不管长度,我的能运行起来就阿弥陀佛
作者: zhengzhenhui 时间: 2024-7-26 22:44
回复 3# 77七
我之前有测试过这种if写一起的,但是我给写到了第9行开始,但是一直运行不成功闪一下就没了,我放弃了,,,就从第9行底下续上了。。。。我用%%a去变量 又试着用%%b去定义,看你里面写到前面是先用一组变量定义文件夹含义,再去获取文件修改时间+里面的变量相呼应,对比之下应该是我逻辑搞错了
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |