哪位高手能帮我写一个这样的批处理文件
我的一个文件夹内有很多这样的图片,他们都含有类似npx-的字符其中n代表任意一个大于1的整数如120px-,105px-等等我想求一个批处理文件将以上字符删除,只删除以上...
我的一个文件夹内有很多这样的图片,他们都含有类似 npx- 的字符其中n代表任意一个大于1的整数
如120px-, 105px- 等等
我想求一个批处理文件将以上字符删除,只删除以上指定字符
比如 有一张图片是这样的
1821w1000px-A3E68AA5E5918AE6A188E4B.jpg
删除后为 1821wA3E68AA5E5918AE6A188E4B.jpg
1222w93px-E4BBBBE6ADA3E99D9E.jpg
删除后为 1222wE4BBBBE6ADA3E99D9E.jpg 展开
如120px-, 105px- 等等
我想求一个批处理文件将以上字符删除,只删除以上指定字符
比如 有一张图片是这样的
1821w1000px-A3E68AA5E5918AE6A188E4B.jpg
删除后为 1821wA3E68AA5E5918AE6A188E4B.jpg
1222w93px-E4BBBBE6ADA3E99D9E.jpg
删除后为 1222wE4BBBBE6ADA3E99D9E.jpg 展开
3个回答
展开全部
保存为XX.BAT(已测试通过),保存到和要改名文件一起的位置:
@echo off&color f1
setlocal EnableDelayedExpansion
echo/&echo 处理中...&echo/
for /f "delims=" %%a in ('dir/b/a-d "*px-*.*"')do (
set nx=%%a
set nx=!nx:px-=■!
set nxn=!nx:*■=!
call set nx1=%%nx:■!nxn!=%%
set n=0&call :yky
echo %%a ===^> !nx1!!nxn!
ren "%%a" "!nx1!!nxn!")
echo/&echo OK 处理完毕&ping -n 2 127.1>nul&exit
:yky
set/a n-=1
echo.!nx1:~%n%,1!|findstr "[0-9]">nul&&goto :yky
set/a n+=1
set nx1=!nx1:~,%n%!
@echo off&color f1
setlocal EnableDelayedExpansion
echo/&echo 处理中...&echo/
for /f "delims=" %%a in ('dir/b/a-d "*px-*.*"')do (
set nx=%%a
set nx=!nx:px-=■!
set nxn=!nx:*■=!
call set nx1=%%nx:■!nxn!=%%
set n=0&call :yky
echo %%a ===^> !nx1!!nxn!
ren "%%a" "!nx1!!nxn!")
echo/&echo OK 处理完毕&ping -n 2 127.1>nul&exit
:yky
set/a n-=1
echo.!nx1:~%n%,1!|findstr "[0-9]">nul&&goto :yky
set/a n+=1
set nx1=!nx1:~,%n%!
展开全部
@Echo Off
Setlocal EnableDelayedExpansion
for /f "tokens=1,* delims=-" %%i in ('dir /a-d /b *.jpg') do (
Set Str=%%i
Ren %%i-%%j !Str:~0,5!-%%j
)
看到楼上的也写个复杂点的
@Echo Off
SetLocal EnableDelayedExpansion
For /l %%i in (1 1 9) Do Set %%i=a
For /f "tokens=1,2 Delims=-" %%i in ('dir /a-d /b *.jpg') Do (
Call :Er "%%i"
Ren %%i-%%j !str!-%%j
)
Exit
:Er
Set Str=
Set Str=%~1
Set Str=!Str:~0,-2!
:loop
If Defined !Str:~-1! Set Str=!Str:~0,-1! Else Goto :eof
Goto loop
Setlocal EnableDelayedExpansion
for /f "tokens=1,* delims=-" %%i in ('dir /a-d /b *.jpg') do (
Set Str=%%i
Ren %%i-%%j !Str:~0,5!-%%j
)
看到楼上的也写个复杂点的
@Echo Off
SetLocal EnableDelayedExpansion
For /l %%i in (1 1 9) Do Set %%i=a
For /f "tokens=1,2 Delims=-" %%i in ('dir /a-d /b *.jpg') Do (
Call :Er "%%i"
Ren %%i-%%j !str!-%%j
)
Exit
:Er
Set Str=
Set Str=%~1
Set Str=!Str:~0,-2!
:loop
If Defined !Str:~-1! Set Str=!Str:~0,-1! Else Goto :eof
Goto loop
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim NewLine
NewLine = vbcrlf
TabStop = ""
function isFolderExists(fso,folderPath)
if folderPath = empty then exit function
If not FSO.FolderExists(folderPath) Then
msgbox "foloder not exists!please try agian"
folderPath = InputBox("批量替换文件名称"& vbcrlf &"请输入路径[绝对路径],为空则自动退出","")
call isFolderExists(fso,folderPath)
end if
end function
Function doRepWord(Files,filePath,repWord,resWord)
Dim S,file,count,newName
repWord = split(repWord,";")
count = 0
Set fso = CreateObject("Scripting.FileSystemObject")
For Each File In Files
for each repStr in repWord
if instr(File.Name,repStr)<>0 then
newName = replace(file.name,repStr,resWord)
If not fso.FileExists(filePath&"\"&newName) Then
'msgBox "exists"
file.name = newName
count = count + 1
end if
end if
next
Next
doRepWord = count
End Function
sub reName()
dim s,folderPath,repWord,resWord
folderPath = "F:\Exercise\xhtml_info\taobao_images"
folderPath = ""
folderPath = InputBox("批量替换文件名称"& vbcrlf &"请输入路径[绝对路径]","")
Set fso = CreateObject("Scripting.FileSystemObject")
call isFolderExists(fso,folderPath)
if folderPath = empty then exit sub
repWord = InputBox("希望要替换掉的字符,多个字符请用分号[;]隔开!","")
resWord = InputBox("希望将字符替换为:!","")
NewLine = vbcrlf
TabStop = ""
function isFolderExists(fso,folderPath)
if folderPath = empty then exit function
If not FSO.FolderExists(folderPath) Then
msgbox "foloder not exists!please try agian"
folderPath = InputBox("批量替换文件名称"& vbcrlf &"请输入路径[绝对路径],为空则自动退出","")
call isFolderExists(fso,folderPath)
end if
end function
Function doRepWord(Files,filePath,repWord,resWord)
Dim S,file,count,newName
repWord = split(repWord,";")
count = 0
Set fso = CreateObject("Scripting.FileSystemObject")
For Each File In Files
for each repStr in repWord
if instr(File.Name,repStr)<>0 then
newName = replace(file.name,repStr,resWord)
If not fso.FileExists(filePath&"\"&newName) Then
'msgBox "exists"
file.name = newName
count = count + 1
end if
end if
next
Next
doRepWord = count
End Function
sub reName()
dim s,folderPath,repWord,resWord
folderPath = "F:\Exercise\xhtml_info\taobao_images"
folderPath = ""
folderPath = InputBox("批量替换文件名称"& vbcrlf &"请输入路径[绝对路径]","")
Set fso = CreateObject("Scripting.FileSystemObject")
call isFolderExists(fso,folderPath)
if folderPath = empty then exit sub
repWord = InputBox("希望要替换掉的字符,多个字符请用分号[;]隔开!","")
resWord = InputBox("希望将字符替换为:!","")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询