标题: [文件操作] [分享]批处理重命名文件和文件夹并添加数字序号 [打印本页]
作者: Batcher 时间: 2022-6-25 09:37 标题: [分享]批处理重命名文件和文件夹并添加数字序号
【问题描述】- @echo off
- cd /d "%~dp0"
- set "NewFolder=一年一班"
- ren "%~nx1" "%NewFolder%"
- setlocal enabledelayedexpansion
- set "n=1"
- for /f "delims=" %%i in ('dir /b /a-d "%NewFolder%\*.txt"') do (
- ren "%NewFolder%\%%i" "大一 (!n!)%%~xi"
- >"%NewFolder%\大一 (!n!)%%~xi" echo 一年一班
- set /a n+=1
- )
- REM 处理子文件夹
- for /f "delims=" %%i in ('dir /b /ad "%NewFolder%"') do (
- REM 假设只有一个子文件夹
- ren "%NewFolder%\%%i" "%NewFolder%"
- set "n=1"
- for /f "delims=" %%j in ('dir /b /a-d "%NewFolder%\%NewFolder%\*.txt"') do (
- ren "%NewFolder%\%NewFolder%\%%j" "大一 (!n!)%%~xj"
- >"%NewFolder%\%NewFolder%\大一 (!n!)%%~xj" echo 一年一班
- set /a n+=1
- )
- )
复制代码
这个目前是只支持一个子文件夹。如果有多个文件夹应该怎么修改?
或者是子文件夹里面还有一个子文件夹,应该怎么修改?
作者: Batcher 时间: 2022-6-25 09:38
处理多个子文件夹.bat- @echo off
- cd /d "%~dp0"
- set "NewFolder=一年一班"
- setlocal enabledelayedexpansion
-
- REM 处理当前文件夹
- ren "%~nx1" "%NewFolder%"
- call :RenFile "%NewFolder%"
-
- REM 处理子文件夹
- set "FolderN=1"
- for /f "delims=" %%i in ('dir /b /ad "%NewFolder%"') do (
- ren "%NewFolder%\%%i" "%NewFolder% (!FolderN!)"
- call :RenFile "%NewFolder%\%NewFolder% (!FolderN!)"
- set /a FolderN+=1
- )
- goto :eof
-
- :RenFile
- pushd "%~1"
- set "FileN=1"
- for /f "delims=" %%i in ('dir /b /a-d "*.txt"') do (
- ren "%%i" "大一 (!FileN!)%%~xi"
- >"大一 (!FileN!)%%~xi" echo 一年一班
- set /a FileN+=1
- )
- popd
复制代码
作者: pokalifor 时间: 2022-6-26 01:35
虽然我不怎么看得懂,但能感觉到你是比较专业的
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |