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-02 16:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please provide more specific information about the batch file name modification requirements, such as what kind of naming rules need to be followed for batch modification, for example, whether it is to add a prefix, suffix, replace certain characters, etc. Then I can write the corresponding script for you. View 1,463 Replies 11
Original Poster Posted 2006-12-01 09:12 ·  中国 福建 漳州 电信
新手上路
Credits 13
Posts 6
Joined 2006-12-01 08:29
19-year member
UID 72251
Gender Male
Status Offline
Thanks, for example: (A is a constant, B is a variable)

A123.txt After renaming --------> 123.txt

A456.txt After renaming ---------> 456.txt

A999.txt After renaming ---------> 999.txt

ps: (To put it simply, that is, remove the constant A, :)

Also need to be able to scan the entire disk.

Thanks :P:P~~~
Floor 2 Posted 2006-12-01 09:27 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If constant A is of fixed length, you can consider removing A through character truncation operations; if the length is not fixed, the format of set var=!str1:A=! can be used reluctantly, provided that: in the same file name, the string A does not overlap with the rest.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-12-01 09:40 ·  中国 福建 漳州 电信
新手上路
Credits 13
Posts 6
Joined 2006-12-01 08:29
19-year member
UID 72251
Gender Male
Status Offline
Um, the moderator is very enthusiastic, thank you.
Here, for A, I need to use strings. The following is for example [www.163.com]
Can the moderator help write a batch script?
Floor 4 Posted 2006-12-01 11:14 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Here are the translations:

Here are two demonstration codes:


@echo off
:: Use the method of replacing the specified string with empty
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set var=%%i
set var=!var:=!
echo %%i after renaming is !var!
)
pause



@echo off
:: Use the method of discarding fixed-length strings
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set var=%%i
echo %%i after renaming is !var:~13!
)
pause


The content of test.txt is:


123.txt
a bc.txt
d e7f89.txt
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2006-12-02 06:45 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
TV drama renamed, not very perfect
@echo off
setlocal enabledelayedexpansion
echo The default renamed file name is 01.rm
pause
set newname=01.rm
:set /p oldname=Please enter the old file name:
:set /p newname=Please enter the new file name:
set /p num=Please enter the total number of episodes:
for /f "tokens=1,2 delims=." %%i in ("%newname%") do (
set newname1=%%i
set newname2=%%j
)
if "%newname1:~0,1%"=="0" set newname1=%newname1:~1%
:loop
for %%i in (*.*) do (echo %%i |find "0%newname1%" && move %%i 0%newname1%.%newname2%)
if "%newname1%"=="%num%" goto :eof
set /a newname1=%newname1%+1
goto loop
Floor 6 Posted 2006-12-02 07:31 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
test

[ Last edited by a9319751 on 2006-12-5 at 04:41 AM ]
Floor 7 Posted 2006-12-02 17:28 ·  中国 福建 漳州 电信
新手上路
Credits 13
Posts 6
Joined 2006-12-01 08:29
19-year member
UID 72251
Gender Male
Status Offline
Thanks to the moderator and the friend above for your enthusiastic help, and thank you all for your attention.

Well, I registered on this forum and immediately posted a help-seeking post. I'm really a bit embarrassed. Actually, I really want this batch processing to change movie names... Hehe~~ Changing each name one by one is a lot of work, and I don't know batch processing. Helpless~

I tried it. The moderator's batch processing can rename, but it's still limited to the names we listed...

What if we don't know in advance how many such ones with fixed symbols [www.163.com] are in our computer?

Then it's not convenient.

The batch processing of the friend above is still not enough.

Please help improve it if you know how. I'm very grateful...
Floor 8 Posted 2006-12-02 20:08 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Then you need to list all your conditions. Just saying replace constant A, but not giving all possible situations, then I can only give the demo code.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2006-12-02 23:12 ·  中国 福建 漳州 芗城区 电信
新手上路
Credits 13
Posts 6
Joined 2006-12-01 08:29
19-year member
UID 72251
Gender Male
Status Offline
The moderator is here so early, heh. I'm sorry, I didn't make the problem clear.

The effect I want is: After running the batch file, it will first let the user enter the defined constant A[www.163.com],

(Because some movies are not just under one address, so it will be different), then use the batch file to remove the amount with

[www.163.com], and there should be no overwrite prompt phenomenon (if it can more clearly show how many file names we have actually changed this time, generate a ren.txt under the C drive to record it, which is the best), and also filter all files on my computer, such as C, D, E, F drives...

That's the situation. Thank you again!
Floor 10 Posted 2006-12-04 01:33 ·  中国 福建 漳州 电信
新手上路
Credits 13
Posts 6
Joined 2006-12-01 08:29
19-year member
UID 72251
Gender Male
Status Offline
I'm sorry, I need this batch script urgently. Please help if you know how, thank you
Floor 11 Posted 2006-12-04 07:55 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
Renaming Files.bat

@echo off
set /p oldname=Please enter the old file name:
set /p newname=Please enter the new file name:
setlocal enabledelayedexpansion
dir /b . >list.txt
for /f "tokens=1 delims=1" %%i in ("%oldname%") do set name=%%i
if "%name:~-1%"=="0" set name=%name:~0,-1%
if "%name:~-1%"=="0" set name=%name:~0,-1%
if "%name:~-1%"==" " set name=%name:~0,-1%
if "%name:~-1%"==" " set name=%name:~0,-1%
for /f "delims=" %%i in (list.txt) do (
set var=%%i
set var=!var:%name%=!
ren %%i !var!
)
dir /b . >list.txt
for /f "tokens=1,2 delims=1" %%i in ("%oldname%") do set name=%%j
for /f "delims=" %%i in (list.txt) do (
set var=%%i
set var=!var:%name%=!
ren %%i !var!
)
dir /b . >list.txt
for /f "tokens=1,2 delims=." %%i in ("%newname%") do set name=%%j
for /f "delims=" %%i in (list.txt) do echo %%i |find "." || ren %%i %%i.%name%
del list.txt
del %0

Generating Files.bat
for /f %%i in (listfile.txt) do copy listfile.txt %%i

listfile.txt
[YYSoR]Typhoon in That Summer 01. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 02. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 03. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 04. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 05. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 06. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 07. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 08. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 09. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 10. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 11. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 12. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 13. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 14. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 15. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 16. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 17. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 18. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 19. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 20. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 21. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 22. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 23. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 24. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 25. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 26. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 27. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 28. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 29. Mandarin Chinese Subtitles.d-vb.rmvb
[YYSoR]Typhoon in That Summer 30. Mandarin Chinese Subtitles.d-vb.rmvb

When using, place "Renaming Files.bat" in the folder of the movies to be renamed and run it. Please back up your important files before use
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +3 2006-12-04 08:01
Floor 12 Posted 2006-12-04 22:37 ·  中国 广东 中山 电信
新手上路
Credits 9
Posts 5
Joined 2006-12-03 08:21
19-year member
UID 72448
Gender Male
Status Offline
That's amazing, thank you.
Forum Jump: