Is there a way to bulk rename files with overlapping names in Windows?

  • Thread starter DaveC426913
  • Start date
  • Tags
    File pc
In summary, you can bulk rename files in a zillion subfolders (by year/month/day) that were produced by some Mac iPhoto camera software or something, but it is a pain to try to work with these files when you can only see a few at a time. You want to put them all into one folder but many of them have overlapping filenames. Is there any type of utility, or even some sort of macro that would allow you to bulk alter the names on these files so you could put them all in the same folder together?
  • #1
DaveC426913
Gold Member
22,475
6,142
I've got a couple of thousand pictures in a zillion subfolders (by year/month/day) that were produced by some Mac iPhoto camera software or something. (I am on PC.) It is really a pain to try to work with these files when I can only see a few at a time. I'd like to put them all into one folder. Problem is, many of them have overlapping filenames (eg. IMG0001.JPG).

Is there any type of utility, or even some sort of macro that would allow me to bulk alter the names on these files so I could put them all in the same folder together?
 
Computer science news on Phys.org
  • #2
DaveC426913 said:
I've got a couple of thousand pictures in a zillion subfolders (by year/month/day) that were produced by some Mac iPhoto camera software or something. (I am on PC.) It is really a pain to try to work with these files when I can only see a few at a time. I'd like to put them all into one folder. Problem is, many of them have overlapping filenames (eg. IMG0001.JPG).

Is there any type of utility, or even some sort of macro that would allow me to bulk alter the names on these files so I could put them all in the same folder together?

if you were on a mac, I would say do it in automator, but since you are on a PC, why not just write up a perl script to do it?
 
  • #3
If you're using Windows, you could probably use a DOS rename command from the command prompt...
 
  • #4
This is a very crude bash script to copy all your jpgs into one folder.

pmv.sh:

Code:
#!/bin/bash

COUNT=0
EXT="jpg"
PBDIR=""

mkdir $2

find $1 -type f -iname \*.$EXT -print | while read file
do
        PDIR=`dirname $file`

        if [ "$PBDIR" != "$PDIR" ]
        then
                PBDIR=$PDIR
                COUNT=`expr $COUNT + 1`
        fi

        BNAME=`basename $file`
        mv $file "${2}/${COUNT}_${BNAME}"
done

If your on windows you'll need cygwin to run this script.

Create a file called pmv.sh and stick the code inside. Make sure it is executable:

chmod +x pmv.sh

Then run it:

./pmv.sh <base directory to search> <folder name you want to stick your files in>

This script will pre-append a unique number to the jpg based on the folder it came from and then stick the file with the rest of your pictures.

Example:

1_pic1.jpg
1_pic2.jpg
1_pic3.jpg
2_pic1.jpg
2_pic2.jpg
2_pic3.jpg
 
  • #5
dduardo said:
If your on windows you'll need cygwin to run this script.
Thanks. This'll do the job.

Holy jumpin'! How big is this cygwin? I don't want to buy a new hard drive to use it once!
 
Last edited:
  • #6
James R said:
If you're using Windows, you could probably use a DOS rename command from the command prompt...
Yeah, you got any ideas about how that'd be done?
 
  • #7
DaveC426913 said:
Holy jumpin'! How big is this cygwin? I don't want to buy a new hard drive to use it once!

I'm pretty sure there is a lot of junk that you don't need to install. You pick which packages you really need, namely: shellutils, coreutils and bash.

It also isn't my fault you're not running linux.
 
  • #8
While cygwin is a great set of packages for Windows, I wonder if you could get by with an implementation of bash for Windows, like http://www.steve.org.uk/Software/bash/ .

One could also write a version of the script in perl or python and then download a perl package like http://aspn.activestate.com/ASPN/Downloads/ActivePerl/ or a python package like http://www.python.org/ .

One could also try a Windows Script version.
(http://www.fpschultze.de/modules/news/index.php?storytopic=1&start=20 may point to useful examples.) I have no experience with Windows scripting.
 
  • #9
robphy said:
One could also try a Windows Script version.
(http://www.fpschultze.de/modules/news/index.php?storytopic=1&start=20 may point to useful examples.) I have no experience with Windows scripting.

Thanks, Rob. http://www.fpschultze.de/modules/news/ has graciously provided a solution that looks like it will do exactly what I want:

The batch code below copies all files from CD to C:\TARGET using the file name IMG[00001..99999].JPG.

Code:
===== 
@ECHO OFF 
SETLOCAL ENABLEDELAYEDEXPANSION 
SET I=0 
SET CDLETTER=D: 
SET TARGET=C:\IMAGES 
MD %TARGET% >NUL 2>&1 
:LOOP 
ECHO Insert ^(first/next/last^) image CD and press any key. Or press STRG+C to cancel 
PAUSE > NUL 
FOR /R D:\ %%F IN (*.*) DO ( 
SET /A I += 1 
IF !I! GTR 9999 (SET F=IMG!I!.JPG 
) ELSE IF !I! GTR 999 (SET F=IMG0!I!.JPG 
) ELSE IF !I! GTR 99 (SET F=IMG00!I!.JPG 
) ELSE IF !I! GTR 9 (SET F=IMG000!I!.JPG 
) ELSE SET F=IMG0000!I!.JPG 
COPY /Y "%%F" C:\IMAGES\!F! 
) 
GOTO LOOP 
ENDLOCAL 
=====
 

1. How can I rename multiple files at once on a PC?

Bulk file renaming can be done on a PC using different methods such as using a file renaming software, using the command prompt, or using the built-in file renaming function in your operating system.

2. Is there a way to rename multiple files with a specific naming pattern?

Yes, most file renaming software allows you to rename multiple files with a specific naming pattern. You can also use the command prompt to rename files with a specific pattern by using wildcards and text replacement commands.

3. Can I undo a bulk file renaming process?

It depends on the method you used to rename your files. If you used a file renaming software, it may have a feature to undo the renaming process. However, if you used the command prompt or the built-in function of your operating system, you may not be able to undo the renaming process.

4. Is it possible to preview the changes before renaming the files?

Yes, most file renaming software allows you to preview the changes before applying them. This can help you ensure that the files are renamed correctly without any errors.

5. Can I rename files in bulk without changing their file extensions?

Yes, most file renaming software allows you to specify which parts of the file name you want to change, so you can rename the files without changing their file extensions. However, if you use the command prompt or the built-in function of your operating system, you may need to be careful not to accidentally change the file extensions.

Back
Top