Answers:
ren
只能用相同长度的文本替换文本。例如,如果您有文件file1.txt
和file2.txt
,ren file*.txt blah*.txt
则按预期执行操作(现在您有文件blah1.txt
和blah2.txt
)。但是,如果您随后键入ren blah*.txt myfile*.txt
命令,则会炸掉该命令,因为它已重命名blah1.txt
为myfile.txt
(not myfile1.txt
),然后由于该文件已存在而无法重命名blah2.txt
为myfile.txt
。
我有2个解决方案:
所有文件都在同一个文件夹中
在该文件夹的命令提示符处运行以下命令:
for /f "delims=¯" %i in ('dir /b /on') do ren "%i" "._%i"
当子文件夹中有文件并且您想用所需的字符串替换“ n”个前几个字符时,一个完整的解决方案:D
path
:放入""
文件的根路径(例如“ C:\ documents and settings \ user \ desktop \ new文件夹”numfirstchars2replace
:将数字替换为第一个字符(在您的情况下为2)str2put
:放置一个字符串作为新文件名的前缀(在您的情况下为._
)@echo off
::only to tell user what this bat are doing
echo.1.initializing...
::enable that thing to allow, for example, incremental counter in a for loop :)
echo.- EnableDelayedExpansion
SETLOCAL EnableDelayedExpansion
::variables
echo.- variables
:: - place here the absolute root path of your files
set path="put here where are the root folder of your files"
set pathbak=%cd%
set numfirstchars2replace=2
set str2put=._
::go to %path% and its driveletter
echo.- entering the path you want
for /f "delims=¯" %%i in ('echo.%path%') do %%~di
cd %path%
::search all subfolders and save them to a temp file
echo.- searching for subfolders
echo.%path%>%temp%\tmpvar.txt
for /f "delims=¯" %%i in ('dir /s /b /on /ad') do echo."%%i">>%temp%\tmpvar.txt
::execute command for root folder and all found subfolders
echo.
echo.2.executing...
for /f "delims=¯" %%i in (%temp%\tmpvar.txt) do (
cd %%i
echo.- in folder: %%i
for /f "delims=¯" %%j in ('dir /b /on /a-d') do (
set newname=%%j
set newname=!newname:~%numfirstchars2replace%,1000!
echo.- renaming from "%%j" to "%str2put%!newname!"...
ren "%%j" "%str2put%!newname!"
)
)
echo.
echo.3.exiting...
::return to %pathbak% and its driveletter
for /f "delims=¯" %%i in ('echo.%pathbak%') do %%~di
cd %pathbak%
@echo on
Total Commander有一个非常不错的多重重绘工具。
我一直发现Flash Renamer是批量重命名文件的好工具。
它具有试用版和完整版(20美元),并且可以基于元数据重命名文件-对于重命名MP3文件(这是我主要用的文件)非常有用。
如果您正在寻找一种用户友好的批量重命名方法,可以尝试使用免费工具Ant Renamer,您可以执行大量操作,并且在进行任何重命名之前还可以方便地进行预览。在弄乱我的音乐,照片或视频库时,我经常使用它。
我使用了这个免费的File Renamer程序,效果很好。许多不同的过滤器和选项,再加上它使您能够测试结果。可能有些过时的UI,但像冠军一样。