1

I am needing a batch file to remove a certain part from multiple filenames in the same directory.

Example: I have over 80,000+ files with the title like so:

Test Title, The - Conspiracy.zip

I am needing ", The" removed from file names leavin the titles like so:

Test Title - Conspiracy.zip

PS, I am needing this in Batch file only!

Any help is much appreciated! THANX!!!

3 Answers3

2

I found what I needed to use and thank you all for the quick replies and help!

@echo off &setlocal
set currentDirectory="%CD%"
for /f "delims=" %%a in ('dir /b /a-d *, The*.*') do (
set "fname=%%~a"
setlocal enabledelayedexpansion
set "nname=!fname:, The=!"
ren "!fname!" "!nname!"
endlocal
)
0

If you can use a Unix command shell, you could use the mv command in a loop.

You could download cygwin or Git Bash, or if you have Windows 10, you could do this right in the command line (assuming you've updated):

Creating a file like this

#!/bin/bash
for file in *.zip
do
    removedPart=", The"
    mv "${file}" "${file/removedPart/}"
done

You might want to test the command on a single file first to be sure it does what you want. i.e.

file=Test Title, The - Conspiracy.zip
removedPart=", The"
mv "${file}" "${file/removedPart/}"
  • This is assuming you want to rename the file, and not change text within the file. That made the most sense to me considering these are zip files. – TinkerTenorSoftwareGuy Apr 19 '17 at 20:40
  • Actually there are about 75 different extensions this for, but just figued I can use a wildacard to take care of them all. – Todd Thomas Apr 21 '17 at 04:46
-1

You can loop through the contents of the file directory in something like this loop. Batch script loop

Then when you're looping through you can replace the contents of the file name. Look at this: String replacement in batch file

Sorry not more specific as Batch scripting isn't my thing. But this logic should prove to at least be helpful. Someone my post something better.

Community
  • 1
  • 1
Dylan Wright
  • 1,118
  • 12
  • 19
  • I think the OP wants to rename the file, not change text present in the file. – TinkerTenorSoftwareGuy Apr 19 '17 at 20:40
  • 1
    You are right. The end file will have removed the ", The" from the middle of the filename and the add a"The" at the beginning. – Todd Thomas Apr 21 '17 at 04:44
  • 1
    Thanks for following up. For not really working in Batch I think I would've resolved it. People are too critical on here sometimes, I just try to provide an answer where I can. – Dylan Wright Apr 21 '17 at 17:56