标题: [文件操作] [分享]批处理截取文件夹名的一部分对其下文件重命名 [打印本页]
作者: Batcher 时间: 2022-3-24 13:48 标题: [分享]批处理截取文件夹名的一部分对其下文件重命名
【问题描述】
作者: Batcher 时间: 2022-3-24 13:48
【解决方案】- @echo off
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- for /f "delims=" %%i in ('dir /b /ad') do (
- echo 正在处理文件夹:%%i
- for /f "tokens=1-6 delims=-(" %%a in ("%%i") do (
- set "FolderSuffix1=%%c-%%d-%%e-%%f"
- set "FolderSuffix2=%%c-%%d"
- )
- pushd "%%i"
- set "n=0"
- for /f "delims=" %%j in ('dir /b /a-d *.txt') do (
- set /a n+=1
- if !n! equ 1 (
- ren "%%j" "JG-Z-!FolderSuffix1!%%~xj"
- ) else if !n! equ 2 (
- ren "%%j" "YS-!FolderSuffix2!%%~xj"
- ) else if !n! equ 3 (
- ren "%%j" "WT-!FolderSuffix2!%%~xj"
- ) else if !n! equ 4 (
- ren "%%j" "邮件%%~xj"
- )
- )
- popd
- )
复制代码
作者: Batcher 时间: 2022-3-24 16:39
帮我改下,第一个文件的文件名直接复制文件夹的名不要后面括号那一截就行
- @echo off
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- for /f "delims=" %%i in ('dir /b /ad') do (
- echo 正在处理文件夹:%%i
- for /f "tokens=1-6 delims=-(" %%a in ("%%i") do (
- set "FolderSuffix1=%%a-%%b-%%c-%%d-%%e-%%f"
- set "FolderSuffix2=%%c-%%d"
- )
- pushd "%%i"
- set "n=0"
- for /f "delims=" %%j in ('dir /b /a-d *.txt') do (
- set /a n+=1
- if !n! equ 1 (
- ren "%%j" "!FolderSuffix1!%%~xj"
- ) else if !n! equ 2 (
- ren "%%j" "YS-!FolderSuffix2!%%~xj"
- ) else if !n! equ 3 (
- ren "%%j" "WT!FolderSuffix2!%%~xj"
- ) else if !n! equ 4 (
- ren "%%j" "邮件%%~xj"
- )
- )
- popd
- )
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |