文件名(夹)编辑选择操作。

@echo off
color 9f
mode con cols=46 lines=10
:memu0
title 操作选择
if exist "%windir%\System32\choice.exe" goto a
cls
:c
echo  [1]输出路径的文件夹结构。
echo  [2]删除文件名(夹)中间字符
echo  [3]除文件名中间的字符
echo  [4]添加文件名前缀
echo  [5]添加文件名序号前缀
echo  [6]替换文件名(夹)名的内容
echo  [0]退出
echo.
set /p d=请输入:
if %d%==1 goto choice1
if %d%==2 goto choice2
if %d%==3 goto choice3
if %d%==4 goto choice4
if %d%==5 goto choice5
if %d%==6 goto choice6
if %d%==x exit
clsnul&cls&goto c
:a
echo  [1]输出路径的文件夹结构。
echo  [2]删除文件名(夹)中间字符
echo  [3]除文件名中间的字符
echo  [4]文件名(夹)添加前缀
echo  [5]文件名添加序号前缀
echo  [6]替换文件名(夹)名的内容
echo  [0]退出
echo.
choice /c 1234560 /m 请选择
if errorlevel 1 if not errorlevel 2 goto choice1
if errorlevel 2 if not errorlevel 3 goto choice2
if errorlevel 3 if not errorlevel 4 goto choice3
if errorlevel 4 if not errorlevel 5 goto choice4
if errorlevel 5 if not errorlevel 6 goto choice5
if errorlevel 6 if not errorlevel 7 goto choice6
if errorlevel 7 exit
clsnul&cls&goto a
:choice1
cls
title 批处理输出驱动器或路径的文件夹结构。
del /s /q /f !treelog.txt
tree /a /f >>!treelog.txt
exit
:choice2
cls
title 批处理删除文件名(夹)中的字符
setlocal ENABLEDELAYEDEXPANSION
set /p str=请输入要删除的字符(回车确认)
for /f "tokens=*" %%a in ('dir/b') do (
set new=%%a
set new=!new:%str%=!
ren "%%a" !new!
)
exit
:choice3
cls
title 批处理删除文件名中的字符
setlocal ENABLEDELAYEDEXPANSION
set /p str=请输入要删除的字符(回车确认):
for /f "delims=" %%a in ('dir /a-d/b *') do (
set new=%%~a
ren "!new!" "!new:%str%=!")
exit
:choice4
cls
title 批处理添加文件名前缀
echo.&set /p strtemp2= 请输入前缀的文件名字符(默认加_):
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir /a /b *.*') do (
ren "%%~a" "%strtemp2%_%%a")
exit
:choice5
cls
title 批处理添加序号前缀
setlocal ENABLEDELAYEDEXPANSION
set num=1000
for %%a in (*) do (
echo.%%a
set /a num+=1
ren "%%a" "!num:~1!_%%a"
)
exit
:choice6
cls
title 批量替换文件名(夹)名的内容
echo 批量替换本文件所在文件夹下所有文件(文件夹)名。
echo.
set /p str1= 请输入要替换的文件名(夹)字符(可替换空格):
set /p str2= 请输入替换后的文件名(夹)字符(去除则留空):
echo.
echo 正在替换文件(文件夹)名……
for /f "delims=" %%a in ('dir /s /b ^|sort /+65535') do (
if "%%~nxa" neq "%~nx0" (
set "file=%%a"
set "name=%%~na"
set "extension=%%~xa"
call set "name=%%name:%str1%=%str2%%%"
setlocal enabledelayedexpansion
ren "!file!" "!name!!extension!" 2>nul
endlocal
)
)
echo 完成
exit

标签: none

添加新评论