China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 12:16
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Seeking help: How to delete a specific string from a file/folder name View 2,841 Replies 7
Original Poster Posted 2011-01-21 11:53 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Such as some file names are:
x to delete xxxxxxxxxxxxxxxxxxxxxxxx.xxx
xx to delete xxxxxxxxxxxxxxxxxxxxx.xxx
....
xxxxxxxxxxxxxxxxxxxxxxxxx to delete.xxx

How to delete the string [to delete] in the file name

I want to rename, but I don't know how to operate the string.
Floor 2 Posted 2011-01-21 13:02 ·  中国 北京 联通
新手上路
Credits 7
Posts 7
Joined 2011-01-13 11:52
15-year member
UID 180734
Gender Male
Status Offline
At the same time, I would like to ask, I also encountered such a problem.
I used a software to solve it, but if there is such a batch processing code, then changing the file name will be more arbitrary, right?
Floor 3 Posted 2011-01-21 13:34 ·  中国 湖北 武汉 电信
初级用户
beginner
Credits 26
Posts 27
Joined 2011-01-13 23:44
15-year member
UID 180774
Gender Male
Status Offline
Actually, this can be found by searching. I happen to have one here


@echo off
setlocal enabledelayedexpansion
for /r %%i in (*.*) do (
set n=%%~ni
ren "%%i" "!n:eMale=!"
)
pause

Just change emale to what you want to delete, and it's done
路漫漫其修远兮~
Floor 4 Posted 2011-01-21 14:26 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
I looked it up, and since I didn't find it, I'm asking.
I don't know how to look up keywords.
Continue to ask, is the format not supporting Chinese?
Floor 5 Posted 2011-01-21 14:29 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
There is a problem with the publication time here again. It took an hour to check.
Floor 6 Posted 2011-01-21 14:40 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Sorry, I made a mistake just now. It supports Chinese. But I don't know how to support directories.
Floor 7 Posted 2011-01-21 15:46 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
```
@echo off
for /f "delims=" %%i in ('dir /b/s/a') do (
set "i=%%i"
set "n=%%~nxi"
setlocal enabledelayedexpansion
ren "!i!" "!n:要删除=!"
endlocal
)
```
Floor 8 Posted 2014-05-11 20:37 ·  中国 福建 福州 电信
新手上路
Credits 1
Posts 1
Joined 2010-06-17 21:39
16-year member
UID 169017
Gender Male
Status Offline
Learned...
Forum Jump: