标题: [其他] 求助完善“删除或者替换当前目录下所有文件夹名称中的指定字符串”批处理代码 [打印本页]
作者: lijinan 时间: 2016-4-8 14:02 标题: 求助完善“删除或者替换当前目录下所有文件夹名称中的指定字符串”批处理代码
本帖最后由 pcl_test 于 2016-4-8 21:32 编辑
- set find_string=
- set /p find_string=输入要查找的字符串:
- if not defined find_string echo 未输入需要查找的字符串! & goto loop1
- set replace_string=
- set /p replace_string=输入替换后的字符串:
- for /f "delims=" %%a in ('dir /b /a-d /ad') do (
- set "str=%%~na"
- setlocal enabledelayedexpansion
- for %%i in ( "!str:%find_string%=%replace_string%!") do (
- endlocal
- rename "%%a" "%%~i%%~xa"
- )
- )
复制代码
上述代码在当前文件夹目录名称中存在.或者!时无法正常进行,求完善,多谢。
作者: happy886rr 时间: 2016-4-8 14:46
本帖最后由 happy886rr 于 2016-4-9 00:02 编辑
- 未输入需要查找的字符串!
- @echo off&cls
- set/p st1=查找的字:
- if not defined st1 (sort %0|more +12&goto loop1)
- set/p st2=替换的字:
- if not defined st2 (sort %0|more +12&goto loop1)
- for /f "delims=" %%a in ('dir /ad /b /s^|sort /r') do (
- set "str=%%~na"
- call,set "str=%%str:%st1%=%st2%%%"
- call,rename "%%a" "%%str%%%%~xa"
- )
- :loop1
- set/p=这里是 loop1^_^&&set/p=
复制代码
回复 1# lijinan
作者: pcl_test 时间: 2016-4-8 21:02
本帖最后由 pcl_test 于 2016-4-8 23:07 编辑
- //&cls&dir /ad /b /s|sort /r|cscript -nologo -e:jscript "%~f0" "查找的字符串" "替换后的字符串"&pause&exit
-
- //如果未指定“替换后的字符串”,则为删除/去除“查找的字符串”
- var fso = new ActiveXObject('Scripting.FileSystemObject');
-
- try{
- var astr = WScript.Arguments(0), bstr = WScript.Arguments(1);
- }
- catch(e){
- try{
- var astr = WScript.Arguments(0), bstr = '';
- }catch(e){}
- }
-
- while(!WScript.StdIn.AtEndOfStream){
- var fd = fso.GetFolder(WScript.StdIn.ReadLine());
- var fn = fd.Name;
- try{
- while(fn.indexOf(astr)>-1){
- var fn = fn.replace(astr, bstr);
- }
- fd.Name = fn;
- }catch(e){}
- }
复制代码
作者: WHY 时间: 2016-4-8 23:33
- @if (0)==(0) echo off
- set "替换前=ABC"
- set "替换后=123"
- for /f "tokens=1*delims=/" %%i in ('dir /b /ad /s^|sort /r^|cscript //nologo //e:jscript "%~0" "%替换前%" "%替换后%"')do (
- ren "%%j" "%%i"
- )2>nul
- pause & exit
- @end
-
- var arg = WSH.Arguments;
- var reg = new RegExp(arg(0).replace(/[\^$(){}\[\]+\-.]/g, '\\$&'), 'ig');
- var str = WSH.StdIn.ReadAll().replace(
- /.+\\(.+)\r\n/g,
- function(s0, s1){
- if (reg.test(s1)) return s1.replace(reg, arg(1)) + '/' + s0;
- }
- )
- WSH.Echo(str)
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |