Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Bulk file renaming - PC

  1. Sep 25, 2005 #1

    DaveC426913

    User Avatar
    Gold Member

    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?
     
  2. jcsd
  3. Sep 25, 2005 #2
    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?
     
  4. Sep 25, 2005 #3

    James R

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    If you're using Windows, you could probably use a DOS rename command from the command prompt...
     
  5. Sep 26, 2005 #4

    dduardo

    User Avatar
    Staff Emeritus

    This is a very crude bash script to copy all your jpgs into one folder.

    pmv.sh:

    Code (Text):

    #!/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
     
  6. Sep 26, 2005 #5

    DaveC426913

    User Avatar
    Gold Member

    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: Sep 26, 2005
  7. Sep 26, 2005 #6

    DaveC426913

    User Avatar
    Gold Member

    Yeah, you got any ideas about how that'd be done?
     
  8. Sep 26, 2005 #7

    dduardo

    User Avatar
    Staff Emeritus

    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.
     
  9. Sep 26, 2005 #8

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    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.
     
  10. Sep 27, 2005 #9

    DaveC426913

    User Avatar
    Gold Member

    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 (Text):
    =====
    @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
    =====
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Bulk file renaming - PC
  1. Analog audio bulk wire (Replies: 12)

Loading...