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 11:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help]Newcomer's Inquiry - Improvement of "Batch Rename Suffix.bat" View 1,880 Replies 6
Original Poster Posted 2011-01-21 14:42 ·  中国 四川 成都 电信
新手上路
Credits 12
Posts 13
Joined 2010-03-03 10:47
16-year member
UID 161489
Gender Male
Status Offline
The code is as follows:

@echo off
:0
cls
echo.
echo. ╭────────╮
echo. ╭────┤ Usage Instructions ├────╮
echo. │ ╰────────╯ │
echo. │ │
echo. │ 1、The purpose of this tool is - batch modify files with specified suffixes in the specified directory to other specified suffixes. │
echo. │ │
echo. │ 2、Please press Enter after each input! │
echo. │ │
echo. │ 3、Note - only enter the suffix, do not enter the "." before the suffix │
echo. │ │
echo. │ 4、If there are spaces and special characters in the folder path, please type it in manually, do not drag and drop! │
echo. │ │
echo. ╰──────────────────╯
echo.&echo Please enter the path of the folder, or drag and drop the folder to this window
set LJ=
set /p LJ=
if /i "%LJ%"=="" goto 0
echo.&echo Please enter the original suffix name:
set q=
set /p q=
if /i "%q%"=="" goto 0
echo.&echo Please enter the new suffix name:
set h=
set /p h=
if /i "%h%"=="" goto 0
cd %LJ%
REN *.%q% *.%h%
echo.&echo. Suffix names have been batch modified successfully!
echo.&echo. Please open the folder and take a look!
start %LJ%
pause
goto 0

This batch processing is my original work and is basically successful.

The questions are -
1、When there are spaces and special characters in the folder path, how to support drag and drop?
2、If you want to process all subdirectories under the folder at the same time, how to write it?
3、In order to avoid being detected, I also want to go further: "While batch modifying the suffix name, batch modify the file name".
That is - add a number 1 between the first character and the second character of the file name.
How to write this?
4、For example, I want to change all "*.cpl" files in "C:\WINDOWS\system32" to "all suffix names uniformly changed to bbb, and a number 1 is added between the first character and the second character of the file name".
In this case, how to write the batch processing to restore the original file name and suffix?

Looking forward to the expert's answer!

Thanks in advance!!!

Kowtow......
Floor 2 Posted 2011-01-21 14:46 ·  中国 四川 成都 电信
新手上路
Credits 12
Posts 13
Joined 2010-03-03 10:47
16-year member
UID 161489
Gender Male
Status Offline
This batch script, if used to "prohibit using the Control Panel", is不知 how much better than the codes spread online......

Hehe......
Floor 3 Posted 2011-01-21 16:35 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Changing the CPL extension and prohibiting the use of the Control Panel are two different things.

The sensitive characters that should not be processed still cannot be processed: support drag-and-drop, support double-click, support filtering, support mixing of files and directories during drag-and-drop
@echo off
rem Set source extension
set x0=.bat
rem Set target extension
set x1=.cmd
rem Set inserted character
set c=1
echo Starting
if "%~1"=="" (
set m=1
goto:b
)
:a
set "a=%~a1"
if "%a:~0,1%"=="-" set d==
if defined d (
if /i "%~x1"=="%x0%" (
set "a=%~n1%x1%"
setlocal enabledelayedexpansion
ren "%~1" "!a:~0,1!%c%!a:~1!"
endlocal
) else echo Not processed; "%~1"
)
:b
if not defined m set n="%~1\"
if not defined d for /r %n% %%a in (*) do if /i "%%~xa"=="%x0%" (
set "a=%%~na%x1%"
setlocal enabledelayedexpansion
ren "%%a" "!a:~0,1!%c%!a:~1!"
endlocal
) else echo Not processed; "%%a"
if defined m goto:end
shift
set d=
if not "%~1"=="" goto:a
:end
echo;Completed
pause


[ Last edited by Hanyeguxing on 2011-1-21 at 17:00 ]
Floor 4 Posted 2011-01-21 16:43 ·  中国 四川 成都 电信
新手上路
Credits 12
Posts 13
Joined 2010-03-03 10:47
16-year member
UID 161489
Gender Male
Status Offline
Originally posted by Hanyeguxing at 2011-1-21 16:35:
Changing the .cpl extension and prohibiting the use of the Control Panel are two different things
The sensitive characters that cannot be processed still cannot be processed:
@echo off
rem Set source extension
set x0=.bat
rem Set target extension
set x1=.c ...


1、First of all, thank you!!

2、I have tested that after changing all the ".cpl" files in "C:\WINDOWS\system32" to ".bbb" extensions, no Control Panel items can be used!

3、The method of prohibiting the Control Panel by modifying the registry circulating on the Internet is ineffective for some computers. For example, my own computer.

4、The most difficult thing is - how to use a batch script to change it back. Do you have a good code?

5、Also, your code cannot be packaged into an exe for novice users to use. But my code can

[ Last edited by lujice on 2011-1-21 at 16:45 ]
Floor 5 Posted 2011-01-21 16:54 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
1, Why pack a bat into an exe for no reason?
2, For the sample I wrote for you, do you still need to copy it exactly?

[ Last edited by Hanyeguxing on 2011-1-21 at 17:04 ]
Floor 6 Posted 2011-01-21 20:13 ·  中国 广东 深圳 电信
初级用户
Credits 32
Posts 32
Joined 2010-10-29 05:31
15-year member
UID 176702
Gender Male
Status Offline
Learned.

Let me say an off-topic thing!

Brother Hanye, can this effect of bundling love and hate in the picture be done with batch processing? If it can, can you show me the code?
Floor 7 Posted 2011-01-22 15:51 ·  中国 四川 成都 电信
新手上路
Credits 12
Posts 13
Joined 2010-03-03 10:47
16-year member
UID 161489
Gender Male
Status Offline
Strange!
Why does creating a recycle bin support spaces and special characters again?


@echo off
:0
cls
echo.
echo. ╭────────╮
echo. ╭────┤ Usage Instructions ├────╮
echo. │ ╰────────╯ │
echo. │ │
echo. │ 1、The purpose of this tool is - to create a recycle bin in the specified directory │
echo. │ inside. │
echo. │ │
echo. │ 2、Please press Enter after each input! │
echo. │ │
echo. │ 3、Supports folder names and paths containing │
echo. │ spaces and special characters! │
echo. │ │
echo. │ 3、When manually entering the folder name and path, and the recycle bin name, please add English double quotes before and after - " │
echo. │ │
echo. ╰──────────────────╯
echo.&echo Please enter the folder path, or drag and drop the folder into this window
set mulu=
set /p mulu=
echo.&echo Please enter the name of the recycle bin:
set /p minzi=
md %mulu%\%minzi%>nul 2>nul
attrib +s +h %mulu%\%minzi%>nul 2>nul
(echo [.ShellClassInfo]
echo CLSID={645FF040-5081-101B-9F08-00AA002F954E})>%mulu%\%minzi%\desktop.ini
attrib +s +h %mulu%\%minzi%\desktop.ini
echo.&echo. Recycle bin created successfully!
echo.&echo. Go and open it manually!
echo.
pause
goto 0
Forum Jump: