如果我在一个目录中有多个文件,并且想把某些东西附加到它们的文件名中,而不是附加到扩展名中,我该怎么做?
我已经尝试了以下,testing文件file1.txt
和file2.txt
:
ren *.txt *1.1.txt
这将文件重命名为file1.1.txt
和file2.txt1.1.txt
我想要的文件是file1 1.1.txt
和file2 1.1.txt
这将成为可能从cmd或我需要有一个bat文件来做到这一点? 那么PowerShell呢?
for /f "delims=" %%i in ('dir /b /ad *.txt') do ren "%%~i" "%%~ni 1.1%%~xi"
如果使用不带/f
参数的简单for
循环,则已重命名的文件将被重新命名。
确保还有更多?
比最长的名字中有人物:
ren *.txt "???????????????????????????? 1.1.txt"
请参阅Windows RENAME命令如何解释通配符? 获取更多信息。
新解决方案 – 2014/12/01
对于那些喜欢正则表达式的人来说,有JREN.BAT – 一个混合的JScript /批处理命令行工具,可以在XP的任何版本的Windows上运行。
jren "^.*(?=\.)" "$& 1.1" /fm "*.txt"
要么
jren "^(.*)(\.txt)$" "$1 1.1$2" /i
下面的命令将完成这项工作。
forfiles /M *.txt /C "cmd /c rename @file \"@fname 1.1.txt\""
来源: 批量重命名文件扩展名
@echo off for %%f in (*.txt) do ( ren "%%~nf%%~xf" "%%~nf 1.1%%~xf" )
步骤1:
选择所有文件(ctrl + A)
第2步 :
然后选择重命名选项
第3步:
选择你的文件名…例如: myfile
它自动重命名为myfile(01),myfile(02),, …..
如果要替换空格和括号,请继续步骤4
步骤4:
从当前文件夹打开Windows Powershell
第5步:
用空格替换下划线(_)
dir | rename-item -NewName {$_.name -replace [Regex]::Escape(" "),"_"}
第六步:
用于更换开放支架
dir | rename-item -NewName {$_.name -replace [Regex]::Escape("("),""}
用于替换紧支架
dir | rename-item -NewName {$_.name -replace [Regex]::Escape(")"),""}
试试这个批量重命名工具它运作良好。 也许不会重新发明轮子。 如果你不需要脚本,这是一个好方法。
我尝试直接粘贴Endoro的命令(谢谢Endoro)到命令提示符添加前缀到文件,但遇到错误。 解决方案是减少%%到%,所以:
for /f "delims=" %i in ('dir /b /ad *.*') do ren "%~i" "Service.Enviro.%~ni%~xi"
我也为此感到困惑…不喜欢当你批量重命名时窗口放入的圆括号。 在我的研究中,我决定用PowerShell编写脚本。 超级简单,像一个魅力工作。 现在我可以使用它,每当我需要批处理文件重命名…这是频繁的。 我拿了数百张照片和相机命名他们IMG1234.JPG等…
这是我写的脚本:
# filename: bulk_file_rename.ps1 # by: subcan # PowerShell script to rename multiple files within a folder to a # name that increments without (#) # create counter $int = 1 # ask user for what they want $regex = Read-Host "Regex for files you are looking for? ex. IMG*.JPG " $file_name = Read-Host "What is new file name, without extension? ex. New Image " $extension = Read-Host "What extension do you want? ex. .JPG " # get a total count of the files that meet regex $total = Get-ChildItem -Filter $regex | measure # while loop to rename all files with new name while ($int -le $total.Count) { # diplay where in loop you are Write-Host "within while loop" $int # create variable for concatinated new name - # $int.ToString(000) ensures 3 digit number 001, 010, etc $new_name = $file_name + $int.ToString(000)+$extension # get the first occurance and rename Get-ChildItem -Filter $regex | select -First 1 | Rename-Item -NewName $new_name # display renamed file name Write-Host "Renamed to" $new_name # increment counter $int++ }
我希望这对那里的人有帮助。
subcan