简体   繁体   English

如何使用BATCH文件为文件夹中的所有文件添加和删除后缀

[英]How to add and remove postfix for all files in folder using BATCH File

I'm trying to add and remove postfix from specific file types in all folders and subfolder. 我正在尝试从所有文件夹和子文件夹中的特定文件类型添加和删除后缀。
I know the code for adding prefix but I don't know the code for postfix 我知道添加前缀的代码,但不知道后缀的代码

Here is my code for prefix 这是我的前缀代码

Adding PreFix: 添加预修复:

@echo off
pushd "D:\Temp\Test\"
for /F "delims=" %%j in ('dir /s /b *.avi *.mkv *.mp4 *.wmv *.mpeg *.flv *.dat *.mov *.asf *.3gp *.srt') do (
   rename "%%j" "[my.prefix]-%%~nxj"
)
popd

Removing PreFix: 删除预修复:

@echo off
pushd "D:\Temp\Test\"
for /F "delims=" %%a in ('dir /s /b *.avi *.mkv *.mp4 *.wmv *.mpeg *.flv *.dat *.mov *.asf *.3gp *.srt') do (
    set "fname=%%~nxa"
    set "fpath=%%~dpa"
    setlocal enabledelayedexpansion
    set "nname=!fname:~15!"
    ren "!fpath!!fname!" "!nname!"
    endlocal
)
popd

How to do this for postfix? 如何针对后缀执行此操作?

Add suffix 添加后缀

@echo off
pushd "D:\Temp\Test\"
for /F "delims=" %%j in ('dir /s /b *.avi *.mkv *.mp4 *.wmv *.mpeg *.flv *.dat *.mov *.asf *.3gp *.srt') do (
   rename "%%j" "%%~nj-[my.suffix]%%~xj"
)
popd

Remove suffix 删除后缀

@echo off
pushd "D:\Temp\Test\"
for /F "delims=" %%a in ('dir /s /b *.avi *.mkv *.mp4 *.wmv *.mpeg *.flv *.dat *.mov *.asf *.3gp *.srt') do (
    set "fname=%%~nxa"
    setlocal enabledelayedexpansion
    set "nname=!fname:-[my.suffix]=!"
    ren "%%a" "!nname!"
    endlocal
)
popd
set fileName=thisIsATest_0001
set fileExtension=.avi

echo %fileName:~0,-5%%fileExtension%

Negative values in second part of substring indicate distance from end of string 子字符串第二部分中的负值表示距字符串结尾的距离

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用此批处理文件将所有* .txt文件从子文件夹复制到批处理文件文件夹? - How to copy all *.txt files from subfolder to batch file folder using this batch-file? 批处理文件以计算文件夹中的所有文件和子文件夹文件,并使用批处理文件以文件夹名称写入输出文件 - batch file to count all files in a folder and subfolder files and write output file in folder name using batch file 使用批处理删除文件夹中除列表中的文件以外的所有文件 - Delete all files in folder except file in list using batch 如何使用批处理文件向当前文件夹和子文件夹中的所有文件添加前缀 - How to Add prefix to all file in current folder and subfolder using batch file 如何在批处理文件中使用for循环列出文件夹中所有文件和目录的名称 - How to list the names of all the files and directories in a folder using for loop in a batch file 如何使用批处理文件以编号顺序列出文件夹中特定扩展名的所有文件 - How to list all files of specific extensions inside a folder with numbering order using batch file 批处理文件:如何将所有 .doc 文件备份到文件夹 - Batch-file: how to backup all .doc files to a folder 从当前文件夹中的所有文件以及子文件夹Windows批处理中的文件中删除前缀 - Remove Prefix from all file in current folder as well as files in subfolder windows batch 批处理文件删除除最新的10个文件以外的所有文件 - batch file remove all but the newest 10 files 使用批处理文件重命名文件夹中的.jpg文件 - renaming .jpg files in a folder using batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM