Reputation: 19
I already found some solution for renaming files. Some did not really work, some only added a suffix after the file ending like
@echo off
Setlocal enabledelayedexpansion
For %%a in (*.*) Do (
Ren "%%a" "%%a Tenor 1"
)
Pause&Exit
My problem: I have several filetypes in a folder like:
song1.mp3
song2.mp3
Text1.txt
Text2.txt
Document1.pdf
Document2.pdf
Add_Tenor_1.bat
Add_Tenor_2.bat
ReplaceBlankwithUnderline.bat
and so on. Now i want to add for example to all files except for the batch files a suffix like "* Tenor 1".
song1 Tenor 1.mp3
song2 Tenor 1.mp3
Text1 Tenor 1.txt
Text2 Tenor 1.txt
Document1 Tenor 1.pdf
Document2 Tenor 1.pdf
Add_Tenor_1.bat
Add_Tenor_2.bat
ReplaceBlankwithUnderline.bat
Is it possible to use *.*
in a for condition with an exception (for .bat) ?
How would the code for the batch file look like?
Another thing is to add the suffix only for .txt and .pdf files for example. Does this work in one routine or do i need one for .txt and one for .pdf?
song1.mp3
song2.mp3
Text1 Tenor 1.txt
Text2 Tenor 1.txt
Document1 Tenor 1.pdf
Document2 Tenor 1.pdf
Add_Tenor_1.bat
Add_Tenor_2.bat
ReplaceBlankwithUnderline.bat
And how would the code for this batch file look like?
Thank you a lot!
And i know there are Programms like Renamer. But as i always want to ad the same (not at the same time) it is quicker to press just the batch instead of opening choosing and renameing it with a porgramm :)
regards chrisdi91
Upvotes: 0
Views: 657
Reputation:
I'll post my batch just to show the exclusion and inclusion ways in one batch just to demonstrate.
@echo off
Setlocal enabledelayedexpansion
Set "Exclude=.bat$ .cmd$ .exe$ .vbs$ "
Set "Include=*.txt *.pdf"
For /f "Delims=" %%a in (
'Dir /B %Include% ^| findstr /i /V "%Exclude%" '
) Do Echo Ren "%%a" "%%~na Tenor 1%%~xa"
Pause
Goto :Eof
Ren "Document1.pdf" "Document1 Tenor 1.pdf"
Ren "Document2.pdf" "Document2 Tenor 1.pdf"
Ren "Text1.txt" "Text1 Tenor 1.txt"
Ren "Text2.txt" "Text2 Tenor 1.txt"
Ren "vm_fire.txt" "vm_fire Tenor 1.txt"
Ren "vm_idle.txt" "vm_idle Tenor 1.txt"
Upvotes: 1
Reputation: 80003
For %%a in (*.*) Do IF /i "%%~xa" neq ".bat" (
Meaning "if the eXtension part of the filename (~%%xa
) is NEQ (not equal to) '.bat' (/i
means case-insensitive comparison)"
See for /? |more
from the prompt for documentation.
BTW - "wanna" is not a word.
Upvotes: 2