Bulk file renaming - PC

  • #1
DaveC426913
Gold Member
18,562
2,029

Main Question or Discussion Point

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?
 

Answers and Replies

  • #2
379
0
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
James R
Science Advisor
Homework Helper
Gold Member
600
15
If you're using Windows, you could probably use a DOS rename command from the command prompt...
 
  • #4
dduardo
Staff Emeritus
1,898
3
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
DaveC426913
Gold Member
18,562
2,029
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
DaveC426913
Gold Member
18,562
2,029
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
dduardo
Staff Emeritus
1,898
3
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 alot 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
robphy
Science Advisor
Homework Helper
Insights Author
Gold Member
5,463
681
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
DaveC426913
Gold Member
18,562
2,029
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. Frank Schultze 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 
=====
 

Related Threads for: Bulk file renaming - PC

Replies
4
Views
2K
Replies
24
Views
5K
Replies
7
Views
100K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
7
Views
5K
  • Last Post
Replies
12
Views
3K
Replies
4
Views
7K
  • Last Post
Replies
3
Views
2K
Top