-2

I have nearly 4,000 image files that I need to rename. They all contain one type of unique ID number (let's call it ID1) along with some other words, and I need to rename them to a different type of unique ID number (let's call it ID2) without the other words. I have the 4,000 ID1 numbers and the ID2 numbers that go along with each one in an excel sheet. Is there a way to do a find and replace that will find each unique ID1 regardless of other words in the name, and replace the entire name with ID2? Here is an example of what I need done:

Original File Name: "Discovery.123456.jpg"

What I need to change it to: "789123.jpg"

All 4,000 files are named individually, and I need to change them to different individual names.

1

You can use a batch-file to do this:

for %%i in (<folder with the images>) do (set var=%%~i
    ren "%%~i" %var:~10%)

Which renames all of the files in the folder to remove the first 10 digits of the file name to become 123456.jpg from Discovery.123456.jpg. You can also have a text file with each ID1 and do this in powershell:

$file = <filepath of text file>
cd <folder with images>
foreach ($line in $file){
$names = @((dir -name | findstr /i $line))
$namesf = $names.trimstart("$line")
for ($i = 0; $i < $names.length; $i++){
ren $names[$i] $namesf[$i]
}
}

What this does is that it checks every line in the text file with all the ID1s and finds them in the folder, removes the ID1 from the beginning of the filename and stores it in a variable and then renames them to the variable. It works with multiple things with ID1 at a time as well.

Good Luck!

| improve this answer | |
  • Remember to add the correct file extensions! .ps1 for powershell and .bat for batch! – SP Tutors May 21 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.