批处理代码修改文件名,去掉字母数字,只留下中文字符,不要改动后缀名。 要求代码要简化
以下两行给以测试:
至上励合 - 棉花糖 - 3edcf06e2e701249db08e3c656ed7d8d.lrc
郑源 - 我不恨你 - 909b0e5489433070aeecad2dbc58d3a5.lrc
------------------------------------
现已有答案不够简化,不理想,参考如下:- @echo off&setlocal enabledelayedexpansion
- set/p "fp=请拖放要进行改名的文件夹到此: "
- pushd "%fp%"
- cls
- for /f "delims=" %%a in ('dir/b/a-d *.*') do (
- set "string=%%~na"
- set "ext=%%~xa"
- set "old=!string!!ext!"
- set "result="
- call :loop
- )
- popd
- echo Done.
- pause
- exit
- :loop
- set "chr="
- set "chr=%string:~0,1%"
- (echo %chr% | findstr "[a-zA-Z0-9]" || set result=%result%%chr%)>nul
- set "string=%string:~1%"
- if "%string%"=="" goto done
- goto loop
- :done
- if not "%result%"=="" (
- echo [!old!] =^> [!result!!ext!]
- ren "!old!" "!result!!ext!"
- )
- exit/b
复制代码 --------------------------------
求大神解答,感谢!!!!!!
-------------------------------- |