Renaming files in sequential order

Automator experts, please help. I am stumped. I manually export photos from iPhoto. When they are exported, the file names are created in the order that they appear in the album. Here's the iss
1. In the Finder, I've got my images listed in order (image1.jpg, image2.jpg, etc...)
2. I select all of the images, and I click the "rename images" plug-in that I created. All it does is take the selected finder items and renames them. I have the action pop up when it is executed.
3. I change the filename to rename sequentially, and I change the filename. For example, the format is: 2006-spring-1.jpg (where "1" is the sequential digit)
4. Well, it renames the files, but messes up the order! image1.jpg should be 2006-spring-1.jpg and image2.jpg should be 2006-spring-2.jpg and so on, but this doesn't happen. image1.jpg may be 2006-spring-6.jpg and so on.
So it does the job, but changes the order. Any idea why this happens? Would creating an Applescript be better? (Not that I know how to do that...)
MacBook Pro 17", iMac G4 800MHz, 60GB iPod (5th Gen)   Mac OS X (10.4.7)  

Try this AppleScript:
tell application "Finder"
set my_folder to folder "untitled folder"
repeat with this_item in (get items of my_folder)
set the_name to name of this_item
set name of this_item to "2006-spring-" & items 6 thru (count the_name) of the_name
end repeat
end tell
The folder's name goes between the quote marks in line 2; different folders in the path can be specified by using : between each element of the path.
(16443)

Similar Messages

  • Rename files in reverse order

    Hi all,
    I'm looking for a script that can rename "n" files inside a folder in reverse order (preserving extension):
    OLD NAME --> NEWNAME
    file1.ext --> file(n).ext
    file2.ext --> file(n-1).ext
    file3.ext --> file (n-2).ext
    file(n) --> file 1
    Is there something available online to do that with Apple Script? I've tried almost al "renamer tools" available but none can do such a thing and I'm not able to script something so this is why I'm asking here
    TIA

    The following script should do what you are asking for, although it is rather slow with folders containing a large number of files. There most likely exist much faster solutions. I hope this one can help anyway. Run the script from the AppleScript Editor.
    *set theFolder to choose folder*
    *tell application "Finder"*
    *   set theFiles to files of theFolder as alias list*
    *   set N to (count theFiles)*
    *   set N2 to 2* * *N + 1*
    *   repeat with thisFile in theFiles*
    *      set {theName, theExtension} to {name, name extension} of thisFile*
    *      set {theName, theNumber} to my rename(theName, theExtension)*
    *      set name of thisFile to theName & (N2 - theNumber) & "." & theExtension*
    *   end repeat*
    *   set theFiles to files of theFolder as alias list*
    *   repeat with thisFile in theFiles*
    *      set {theName, theExtension} to {name, name extension} of thisFile*
    *      set {theName, theNumber} to my rename(theName, theExtension)*
    *      set name of thisFile to theName & (theNumber - N) & "." & theExtension*
    *   end repeat*
    *   set theFolderName to name of theFolder*
    *end tell*
    *tell me to activate*
    *beep 2*
    *display dialog "The " & N & " files of folder “" & theFolderName & "” have been renamed in reverse order." buttons {"OK"} default button 1 with icon 1*
    *on rename(theName, theExtension)*
    *   set L1 to (offset of "." & theExtension in theName) - 1*
    *   set theName to text 1 through L1 of theName*
    *   set theDigits to {}*
    *   repeat with k from 1 to L1*
    *      set thisDigit to item -k of theName*
    *      if thisDigit is in "1234567890" then*
    *         copy thisDigit to the end of theDigits*
          else
    *         exit repeat*
    *      end if*
    *   end repeat*
    *   set theNumber to (reverse of theDigits) as text*
    *   set L2 to length of theNumber*
    *   if L1 = L2 then*
    *      set theName to ""*
       else
    *      set theName to text 1 through (L1 - L2) of theName*
    *   end if*
    *   return {theName, theNumber}*
    *end rename*

  • [Solve] Bash: Rename file in folder to sequential numbers saving path

    I have a folder with many subfolders with many files. I want to rename all files to sequential numbers (0001.jpg, 0002.jpg, .0003,jpg ...) but i want to save the path. I mean that the files should not be saved in the root directory (where i launched the script), but I want them to remain in original subdirectorys. How can i do this?
    Last edited by cypherinside (2011-11-14 18:37:16)

    cypherinside wrote:
    for src in "$1"/*; do ## "$1"/*
    are all the subdirectory. Can i use "$(pwd)/*" instead of "$1/*"? In this way i don't write the parent directory
    If you want to specify $PWD, just call the script with an argument of '.' to point it at PWD.
    cypherinside wrote:
    if [[ -d $src ]];
    walk "$src"
    continue
    fi
    I dont' understand
    It's simple recursion. You don't want to rename directories, you want to process the contents of the directory in the same way you're processing the current directory.
    cypherinside wrote:
    printf -v dest '%s/%04d.jpg' "$1" "$(( ++i ))"
    Stores in dest... what? I assume that %s is a string as in C language, infact you give "$1" as argument (but why?). And I assume that  "$((++i))" is like i=$((i+1)). Is it right?
    It's the bash equivalent of sprintf(3).
    cypherinside wrote:
    [[ $1 ]] || exit 1
    I don't understand.
    If $1 doesn't exist (i.e. you passed no arguments to the script), then refuse to run and exit immediately with an error.
    You weren't really clear in your requirements, so I wrote it as I interpreted it. If you want to reset the numbering for each directory, scope 'i' locally:
    #!/bin/bash
    walk() {
    local -i i=0
    for src in "$1"/*; do
    if [[ -d $src ]]; then
    walk "$src"
    continue
    fi
    printf -v dest '%s/%04d.jpg' "$1" "$(( ++i ))"
    mv "$src" "$dest"
    done
    [[ $1 ]] || exit 1
    walk "$1"

  • Displaying (arranging) files by date or sequential order

    I've uploaded a zip file w/ multiple word/html files; however they need to be listed in sequential order (section 1, section 2, etc.) They are diplaying in random order. I do not see and icon that allows me to rearrange the order of files.
    Suggestions?
    thanks

    The order of items in a content area folder is controlled by the folder layout of the style. By default it should be giving you blue up arrows next to each item. These arrows allow you to move items up and down within the folder. You can also choose to order by file size or title by editing the folder style and selecting the order preference for a specific region of the folder layyout.

  • How can i bulk rename music files in reverse order from artist - song name to songname - artist

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so..
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    Artist - Song Name
    and i need this list to reverse it self so it is listed in the list as
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Song Name - Artist
    Im sure there is some kinda way to auto a mix of applescript/automator/terminal to do something like:  all char before the "-" replace with the chars after the "-".
    Please some one help me if you know how I can pull this off

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so.
    I wonder if we haven't misunderstood what you were asking for. Could it be that you have not a huge file, but just a huge list of names in many small files. If that's the case, you should rather use the following script instead of the previous one.
    Since this script does not rename the files, make a backup of your files before running it.
    set theFolder to choose folder -- the folder containing your text files
    tell application "Finder"
        set theNames to name of files of theFolder whose name extension is "txt"
    end tell
    set theTextFiles to {}
    set theFolderPath to POSIX path of theFolder
    repeat with thisName in theNames
        copy theFolderPath & thisName to the end of theTextFiles
    end repeat
    repeat with thisFile in theTextFiles
        set F1 to open for access thisFile
        set theText to read F1
        close access F1
        set theParagraphs to paragraphs of theText
        set bigList to (a reference to theParagraphs)
        set theNewParagraphs to {}
        set bigNewList to (a reference to theNewParagraphs)
        repeat with X in bigList
            set P to offset of " - " in X
            if P = 0 then
                set Y to X
            else
                set Y to text (P + 3) through -1 of X & " - " & text 1 through (P - 1) of X
            end if
            copy Y & return to the end of bigNewList
        end repeat
        set theNewText to text 1 through -2 of (bigNewList as text)
        set F2 to open for access thisFile with write permission
        set eof F2 to 0
        write theNewText to F2
        close access F2
    end repeat
    display dialog "Done!" buttons {"OK"} default button 1 with icon 1
    Message was edited by: Pierre L.

  • Sedname - Batch rename files using sed

    Renaming files using sed is nothing new, but this script makes the process a little more friendly and adds a few features, including insertion of sequential numbers and a simulation mode.  The output of any find command can also be piped through sedname.
    sedname version 1.0.0
    Batch-renames files using a sed script
    Usage: sedname [OPTIONS] SEDSCRIPT FILE ...
    Usage: find [...] | sedname [OPTIONS] SEDSCRIPT
    Example: sedname 's/\(.*\)\.jpg/\1.jpeg/' *.jpg
    Example: find /mypics | sedname 's/\(.*\)\.jpg/\1.jpeg/'
    OPTIONS:
    --sim simulate only
    --dir rename directories too
    Use #D to insert a number with D digits forming a unique filename
    Example: sedname 's/thisname.*/thatname#3/' *
    ( changes thisname* to thatname001, thatname002, ... )
    Use #0 in replacement name to insert a number if needed
    Example: sedname 's/thisname.*/thatname#0/' *
    ( changes thisname* to thatname, thatname1, thatname2, ... )
    http://igurublog.wordpress.com/download … t-sedname/
    http://aur.archlinux.org/packages.php?ID=37707

    What does it have over zsh's zmv:
    # Remove illegal characters in a fat32 file system. Illegal characters are
    # / : ; * ? " < > |
    # NOTE: ``-Q'' and (D) is to include hidden files.
    $ unwanted='[:;*?\"<>|]'
    $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'
    # Changing part of a filename (i. e. "file-hell.name" -> "file-heaven.name")
    $ zmv '(*)hell(*)' '${1}heaven${2}'
    # or
    $ zmv '*' '$f:s/hell/heaven/'
    # remove round bracket within filenames
    # i. e. foo-(bar).avi -> foo-bar.avi
    $ zmv '*' '${f//[()]/}'
    # serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)
    $ ls *
    1.c asd.foo bla.foo fnord.foo foo.fnord foo.foo
    $ c=1 zmv '*.foo' '$((c++)).foo'
    $ ls *
    1.c 1.foo 2.foo 3.foo 4.foo foo.fnord
    # Rename "file.with.many.dots.txt" by substituting dots (exept for the last
    # one!) with a space
    $ touch {1..20}-file.with.many.dots.txt
    $ zmv '(*.*)(.*)' '${1//./ }$2'
    # Remove the first 4 chars from a filename
    $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
    # Rename names of all files under the current Dir to lower case, but keep
    # dirnames as-is.
    $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
    # replace all 4th character, which is "1", with "2" and so on
    $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'
    # Remove the first 15 characters from a string
    $ touch 111111111111111{a-z}
    $ zmv '*' '$f[16,-1]'
    # Replace spaces (any number of them) with a single dash in file names
    $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'
    # or - with Bash
    $ find . -depth -name '* *' -exec bash -c '
    > shopt -s extglob
    > file=$1
    > dir=${file%/*}
    > name=${file##*/}
    > newname=${name//*([ -]) *([ -])/-}
    > mv -i -- "$file" "$Dir/$newname"' {} {} \;
    # Clean up file names and remove special characters
    $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
    # Add *.py to a bunch of python scripts in a directory (some of them end
    # in *.py and give them all a proper extension
    $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
    # lowercase all extensions (i. e. *.JPG) incl. subfolders
    $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
    # Or - without Zsh
    $ find Dir -name '*.[jJ][pP][gG]' -print | while read f
    > do
    > case $f in
    > *.jpg) ;
    > *) mv "$f" "${f%.*}.jpg" ;
    > esac
    > done
    # remove leading zeros from file extension
    $ ls
    filename.001 filename.003 filename.005 filename.007 filename.009
    filename.002 filename.004 filename.006 filename.008 filename.010
    $ zmv '(filename.)0##(?*)' '$1$2'
    $ ls
    filename.1 filename.10 filename.2 filename.3 filename.4 filename.5 ..
    # renumber files.
    $ ls *
    foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
    $ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
    $ ls *
    foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
    # adding leading zeros to a filename (1.jpg -> 001.jpg, ..
    $ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
    # See above, but now only files with a filename >= 30 chars
    $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'
    # Replace spaces in filenames with a underline
    $ zmv '* *' '$f:gs/ /_'
    # Change the suffix from *.sh to *.pl
    $ zmv -W '*.sh' '*.pl'
    # Add a "".txt" extension to all the files within ${HOME}
    # ``-.'' is to only rename regular files or symlinks to regular files,
    # ``D'' is to also rename hidden files (dotfiles))
    $ zmv -Q '/home/**/*(D-.)' '$f.txt'
    # Or to only rename files that don't have an extension:
    $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
    # Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
    $ chars='[][?=+<>;",*-]'
    $ zmv '(**/)(*)' '$1${2//$~chars/%}'
    # Removing single quote from filenames (recursively)
    $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
    # When a new file arrives (named file.txt) rename all files in order to
    # get (e. g. file119.txt becomes file120.txt, file118.txt becomes
    # file119.txt and so on ending with file.txt becoming file1.txt
    $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'
    # lowercase/uppercase all files/directories
    $ zmv '(*)' '${(L)1}' # lowercase
    $ zmv '(*)' '${(U)1}' # uppercase
    # Remove the suffix *.c from all C-Files
    $ zmv '(*).c' '$1'
    # Uppercase only the first letter of all *.mp3 - files
    $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
    # Copy the target `README' in same directory as each `Makefile'
    $ zmv -C '(**/)Makefile' '${1}README'
    # Removing single quote from filenames (recursively)
    $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
    # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
    $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
    $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively
    (from zsh-lovers)
    Edit: tried it now, and had to remove this silly block to make it let me use alternate delimiters:
    if [ "${sedscript:0:2}" != "s/" ]; then
    echo "Invalid sed script: $sedscript" > /dev/stderr
    exit 1
    fi
    Last edited by JohannesSM64 (2010-05-31 15:29:44)

  • Deleting & renaming files - is there a shortcut to finder?

    I am a recent convert from PC to Mac. So far so good. However, one thing starts to drive me up the wall which is deleting/renaming files in programs such as photoshop, word, excel etc.etc.
    As far as I can tell, this is only possible in the finder menu. Is this Correct? I am using a lot of folders and subfolders - sometimes 3-4 levels deep. Every time I need to change/delete a file or filename - lets say while in photoshop, I have to go to finder and click my way through several levels of folders to the actual file I need to change. This is somewhat annoying and timeconsuming.
    Question 1: is there a way to do these operations in - lets say photoshop directly?
    Question 2: If not, is there a shortcut key that would point me automatically to the file in finder where I can make the changes?
    Your input would be very helpful and save me some aggravation.
    fupe

    Hi Greg,
    Thanks for your input. You are correct as far as "save" and "save as" is concerned. Windows and Mac work the same way.
    However, as far as I can tell, in Mac you can only "delete" or "rename" a file in "finder" which forces you to open up finder and locate the file in order to delete or change it.
    In windows you can do these 2 functions directly in the program (such as photoshop, excel or words). You do not have to go to "explorer or root directory" to make these changes which I believe would be the equivalent of "finder".
    In any case, Terence solved the problem. By command clicking the name (title) of the file in any program, it opens up the directory in "finder". This way makes it easy to select the file and do the changes.
    fupe

  • Automator: Impossible to rename file using automator under Mac OS X Lion

    Hi,
    Before upgrade my iMac to MAC OS X Lion 10.7.2, I had service created with automator under snow leopard in order to rename my pictures file names by blocks instead of one by one. Since I'm using Lion, this one doesn't work anymore. I have completely recreate the service under Lion and the results is the same.
    You can find below my workflow that is easy. The problem is the message error in the history of automator application. The message is "impossible to rename file "file name" because this one should create conflict with existing file". I already test a lot of times with different name where I'm sure that this one doesn't exist on my Mac but all the time without success (verify also with search function under mac)
    If somebody can help me, it would be very interesting because I already tried to find answer on internet without success too.
    Thanks in advance for your help.

    the whole automator and in particular the record action was substantially rewritten in snow leopard. and the record action is slow, unreliable and you can't trouble-shoot it. it's a wonder it works at all. the only advice i can give is to use it as little as possible. if at all possible avoid it altogether. if you do need to use it try using keyboard strokes instead of the mouse movement. for example. use command+c and command+v for copying and pasting and use tabbing to choose the correct box on the page.

  • Up until this latest upgrade to iTunes, all my tv shows were listing in episode sequential order on my iPod.  Now they are only showing up in alphabetical order.  Help?

    I loved my iPod Classic because I would load a television series on it and be able to watch it in Episode Sequential order.  But since this latest update to iTunes, all my television files (while staying seasonally organized) are now listing alphabetically.  Help?  Ideas? Explanation?

    add your release date manually if it isn't there.
    unfortunatly iTunes won't let you do it. i use a program called "TvTagger". just search google, third result from top, that's the one. you have to enter a release date like this: YYYY-mm-dd . I did it and I think it's worth the hassle. not only are your shows sorted correct, but the ugly "Unknown Release Date" line is replaced by the actual release date

  • Combine Files incorrectly rearranges order of files

    Acrobat 9 incorrectly rearranges the order of the files in the Combine Files function when selecting multiple files to move.  For example, I have 40 files that I am combining into one.  Since the files are named 1-40, files 2-9 will not be in order.  If I highlight files 5-9 and drag them up to the spot they belong to put them in order some of the other files that were previously in order now are in random order.  The order might now be 31, 35, 32, 33, 37, etc.  This happens when selecting multiple files and dragging them up or down in the Combine Files window.  Anyone else seen this problem?

    Yeah, I'm aware that renaming files 1-9 to 01-09 will put them in order from the beginning but this doesn't change the fact that if I wanted to move several files that were named something other than by number (ie. TDY report, sales report, etc.) and I selected several to move let's say inbetween files 21-22 several other files that were previously in order now become out of order for no apparent reason.

  • How can I bulk sort by capture time and  bulk rename files off multiple cameras?

    I have found many renaming utilities, including bridge, but I have not run across any that allows bulk / batch capture time sort and rename?
    I can sort by capture time in Lightroom 3, but when I export it puts the files back in original order....maybe I am doing something wrong....that would not surprise me. 
    I just tried sorting by Capture Time in LR3 and then exporting and renaming.... renamed but not in the capture time sort order....    
    so I am open to any suggestions... I shoot 2 cameras 99% of the time so I do not need to change lenses.
    Thanx in advance.

    How can I bulk rename music files in reverse order from artist - song name to songname - artist.
    I actually dont need to rename the actual files.
    Its just i have a huge txt list of 100,000 music names that are listed as so.
    I wonder if we haven't misunderstood what you were asking for. Could it be that you have not a huge file, but just a huge list of names in many small files. If that's the case, you should rather use the following script instead of the previous one.
    Since this script does not rename the files, make a backup of your files before running it.
    set theFolder to choose folder -- the folder containing your text files
    tell application "Finder"
        set theNames to name of files of theFolder whose name extension is "txt"
    end tell
    set theTextFiles to {}
    set theFolderPath to POSIX path of theFolder
    repeat with thisName in theNames
        copy theFolderPath & thisName to the end of theTextFiles
    end repeat
    repeat with thisFile in theTextFiles
        set F1 to open for access thisFile
        set theText to read F1
        close access F1
        set theParagraphs to paragraphs of theText
        set bigList to (a reference to theParagraphs)
        set theNewParagraphs to {}
        set bigNewList to (a reference to theNewParagraphs)
        repeat with X in bigList
            set P to offset of " - " in X
            if P = 0 then
                set Y to X
            else
                set Y to text (P + 3) through -1 of X & " - " & text 1 through (P - 1) of X
            end if
            copy Y & return to the end of bigNewList
        end repeat
        set theNewText to text 1 through -2 of (bigNewList as text)
        set F2 to open for access thisFile with write permission
        set eof F2 to 0
        write theNewText to F2
        close access F2
    end repeat
    display dialog "Done!" buttons {"OK"} default button 1 with icon 1
    Message was edited by: Pierre L.

  • IPhone photo album file name sort order

    I have a folder with photos in it on my Mac.  When I sync the folder to my iPhone and view the photos on the phone, the photos are not displaying in file name sort order.  The file names of the photos are numbers (001, 002, 003 etc.).  It seems the photos are being displayed in date created order and not in the file name order.  The album with photos on my Mac is arranged / sorted by the name when syncing.
    Is there a way to have the photos in the iPhone album displayed in file name sort order?
    Thanks,
    David

    Focus Point (not free, no ads) will allow you to rename the files, add descriptions, and sort in a variety of ways. But it won't let you do anything in the main screen except browse your photo albums or camera roll, select one, and then you can do a search within that album or camera roll--and then if and only if the photo has a filename or description can you search for it. Bottom line: be sure to give your photos a proper file name and add a description.

  • I need an app to search PDF, words not in sequential order. Please help

    Hopefully this means something to someone. I need to search through hundreds of PDF files but need to search for the words in the file name in non sequential order.  Every app that I have looked at so far can search for words in the middle of a file name but type them out of order and it doesn't recognise.
    I hope someone out there can help. Many thanks in advance.

    hullo there
    i know that writepdf lets you search for keywords within actual docs, then it comes up with a list of interactive links of documents that have that keyword
    would that be any good?

  • Rename files using text or excel file

    I am trying to find out how to rename files on my pc using the names stored in a text document
    eg. the file on the pc is called "C07_08.dat"
    the text file has the following line "3am Eternal         KLF         03:15 121 BMG         C07.08"
    i want to change the name of the file "C07_08.dat" to "3am Eternal.mpeg"
    What I would like is a batch file or program or something that will see the text "C07.08" and find the corresponding file "C07_08.dat" and rename it "3am Eternal.mpeg"
    I have managed to create a excel document that has the information in four separate columns
    Column A has the name of the file I want to use (ie. 3am Eternal) Column B & C have unneeded information and Column D has the file reference (ie. C07.08)
    I was told that Python or Visual basic could do this so I downloaded them but I have no experience with this so im lost as to what to do, I have over 1800 of these files so doing it file by file will take quite a while.
    I have included a sample of the text file for reference if that helps
    3am Eternal KLF 03:15 121 BMG C07.08
    4 In The Morning Gwen Stefani 04:22 092 UMA HD1.10
    4 Minutes Madonna ft J Timberlake 04:04 113 WAR HE3.05
    5 6 7 8 Steps 03:24 000 BMG C48.03
    5678 Steps 03:23 140 MUS H16.02
    6 Of 1 Thing Craig David 03:15 116 WAR HE2.11
    60 MPH New Order 03:51 125 WAR N57.11
    7 Days Craig David 04:30 084 SHO N41.16
    7 Things Miley Cyrus 03:29 107 EMI HE7.09
    99 Luft Balloons Nena 03:58 095 WAR C27.10
    99 Times Kate Voegele 03:27 112 UMA HG6.07
    A Girl Like You Edwyn Collins 03:47 126 MDS R06.08
    A Little Bit Pandora 03:35 132 UMA H23.01
    A Little Less Conversation Elvis VS JXL 03:02 115 BMG H68.03
    A Matter Of Trust Billy Joel 04:00 110 SON C59.11
    A New Day Has Come Celine Dion 04:20 092 SON H65.20
    A Woman Like You Mondo Rock 04:03 169 MUS R06.01
    About You Now Sugababes 03:32 083 UMA HD5.08
    Absolutely Everybody Vanessa Amorosi 03:52 124 TRA H40.06
    Absolutely Fabulous Pet Shop Boys 03:45 132 EMI C15.02
    Accidentally In Love Counting Crows 03:08 138 UMA H94.05
    According To You Orianthi 03:18 066 UMA HG4.12
    Achy Breaky Heart Billy Ray Cyrus 03:55 122 SON K11.02

    Here are two VBScripts that will rename the files based on the text file example you provided. The script that reads a
    TEXT FILE requires each entry to be separated by
    ONE TAB  because it is the
    TAB
    that it uses to split each line into 4 parts (part1 - old file name, part2 and part3 - items you don’t need, part 4 - new file name). If there is more that one tab then the Split Function will not work properly.
    The second VBScript will read the
    EXCEL FILE row by row and use the values in Column A for the old file name and
    Column D for the new file name. This approach will work much better if you have an excel document setup like this.
    I used your example that you provided and it test fine for both approaches.
    'Read text file
    Dim objFSO, objFolder, inFile, strInLine, strOldFile, strNewFile
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Select the folder
    Set objFolder = objFSO.GetFolder("C:\Scripts\MusicFiles")
    'Open Text File
    Set inFile = objFSO.OpenTextFile("C:\Scripts\MusicFiles.txt",1)
    Do Until inFile.AtEndOfStream
    'Read text file line by line and Split each line into 4 parts.
    strInLine = Split(inFile.ReadLine, vbTab)
    'Old File name
    strOldFile = strInLine(3)
    'new File name
    strNewFile = strInLine(0)
    'Loop through the files in the folder
    For Each File In objFolder.Files
    'If the file name matches the old file name above
    If File.Name = strOldFile & ".dat" Then
    'Replace it
    File.Name = strNewFile & ".mpeg"
    End If
    Next
    Loop
    'Close the text reader
    inFile.Close
    MsgBox "Done."
    'Read Excel file
    Dim objFSO, objExl, objFolder, objWorkbook, strOldFile, strNewFile, intRow
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objExl = CreateObject("Excel.Application")
    'Select the folder
    Set objFolder = objFSO.GetFolder("C:\Scripts\MusicFiles")
    'Open the Excel file
    Set objWorkbook = objExl.Workbooks.Open("C:\Scripts\MusicFiles.xls")
    'Start at row 1
    intRow = 1
    'Read each Row until the end
    Do Until objExl.Cells(intRow,1).Value = ""
    'Old file name is in column 4
    strOldFile = objExl.Cells(intRow, 4).Value
    'New file name is in column 1
    strNewFile = objExl.Cells(intRow, 1).Value
    'Loop through each file in the selected folder
    For Each File In objFolder.Files
    'If the file name matches the old file name above
    If File.Name = strOldFile & ".dat" Then
    'Replace it
    File.Name = strNewFile & ".mpeg"
    End If
    Next
    'Increment each row
    intRow = intRow + 1
    Loop
    'Close Excel
    objExl.Quit
    MsgBox "Done."
    v/r LikeToCode....Mark the best replies as answers.

  • Renaming files in a book

    Hi everyone,
    I need to rename files in a book, but from within the book. A Save as... won't update the cross refrences.
    I see an fcode for this (FCodes.KBD_BOOKRENAMEFILE), but I've been advised not to rely on these types of shortcuts.
    I don't see anything else documented in the Scripting Guide. Does anyone else have any other suggestions?
    Thanks so much!
    Heather A

    Just following up for anybody else who might need this in the future.
    My hangup was that pulling files from the book itself created Doc objects, not File objects (beginners mistake, you hate to see it). Anyway, here are some of the functions that I came up with to handle this task for anybody who needs it. Please be warned, this is quite literally my first ExtendScript project so this may not be the most efficient way to have done this (I'm always open to constructive criticism from those more experienced than myself). I know I went overkill with notes in the code, that was requested by colleagues who know less about code than I do so that if I were no longer employed for some reason another person could come in and understand exactly what the code was doing.
    function fileNameReplacer(FullArray, CodeBook, BookFile) {
        /*The fileNameReplacer steps through all of the files in the book looking for those who need to be renamed.
            The function first renames all of the files, and then cycles through each file's Crossreferences and updates the
            names to reflect name changes*/
        /*Local variables are created*/
        var FileName,
            BookName,
            FilePath,
            FullName,
            FileType,
            EncodedName,
            OldName,
            NewName,
            ThisFile,
            OpenFile,
            FileArray;
        FileArray = FullArray;
        /*Loops through all of the files in the book*/
        for (var i = 0, len = FileArray.length; i < len; i++) {
            /*Tests if the file is type 255 which would signify it is a folder or a group (These will not be renamed and would throw errors)*/
            if (FileArray[i][0].type == 255) {
                /*If the file is identified as a group or folder, it is removed from the Array with the "splice" command*/
                FileArray.splice(i, 1);
                /*The counters for this loop are then adjusted to reflect the new length of the "FileArray" variable*/
                i = i - 1;
                len = len - 1;
                /*Starts the next round of the loop (which is actually repeating the same loop but without the group or folder in the Array)*/
                continue;
            /*If the file being looked at is not a folder or group, it is assigned to the "ThisFile" variable*/
            ThisFile = FileArray[i][0];
            /*Checks the file to see if it's element catalog has values. If there are no values, it would mean that there is no data from which
                to develop the encoded name, and likely means the file is something like a cover page or table of contents which do not need encoding*/
            if (ThisFile.ElementCatalog.length !== 0) {
                /*If the element catalog has items in it, the name of the current file being examined is assigned to the "FullName" variable*/
                FullName = ThisFile.Name;
                /*The FullName is then split into an array at each backslash (Backslashes in JavaScrip have their own meaning, in order to
                    input a single backslash two must be used). The last item of the array is the file name which is assigned to the "FileName"
                    variable using the "pop" command*/
                FileName = FullName.split("\\").pop();
                /*The FileName is then split at the period, and the file extension with a leading period is assigned to the "FileType" variable.*/
                FileType = "." + FileName.split(".").pop();
                /*The file path without file name is assigned to the "FilePath" variable. This is done by identifying where in the "FullName" variable
                    the "FileName" begins, and then taking a substring of the "FullName" up to that point.*/
                FilePath = FullName.substr (0, (FullName.indexOf(FileName)));
                /*The new encoded file name is found by running the current file through the nameEncoder function along with the Abbreviation List
                    (Called "CodeBook" in this function). The value produced by the nameEncoder function is assigned to the "EncodedName" variable*/
                EncodedName = nameEncoder(ThisFile, CodeBook);
                /*The encoded name and original name are then assigned to locations 2 and 1 in the File array respetively*/
                FileArray[i][2] = FilePath + EncodedName + FileType;
                FileArray[i][1] = FullName;
                /*The old name and new name are compared to see if a change has actually occurred*/
                if (FileArray[i][1] === FileArray[i][2]) {
                    /*If no change has occured, the file is removed from the array using the "splice" command, since it will only slow down later processes.*/
                    FileArray.splice(i, 1);
                    /*The loop counters are updated to reflect the change in FileArray length*/
                    i = i - 1;
                    len = len - 1;
                    /*Starts the next round of the loop (which is actually repeating the same loop but with the file not requiring renaming removed)*/              
                    continue;
            } else {
                /*If the element catalog for the current file does not have any values it is removed from the "FileArray" using the "splice" command*/
                FileArray.splice(i, 1);
                /*The loop counters are updated to reflect the change in FileArray length*/
                i = i - 1;
                len = len - 1;
                /*Starts the next round of the loop (which is actually repeating the same loop but with the file lacking elements removed)*/
                continue;
        /*At this point the FileArray contains only files that can, and have been renamed; along with their current and new names*/
        /*Loops through all files in the FileArray*/
        for (var l = 0, lenA = FileArray.length; l < lenA; l++) {
            /*Assigns the current file, its old name, and its new name to the "ThisFile", "OldName", and "NewName" variables respectively*/
            ThisFile = FileArray[l][0];
            OldName = FileArray[l][1];
            NewName = FileArray[l][2];
            /*Opens the current file assigned to "ThisFile" as a File object. File objects allow for changes on the drive itself to be made, while
                changing the .Name attribute of a Doc object will not. This allows for the encoded names to be applied directly to the files themseves.*/
            OpenFile = File(ThisFile.Name);
            OpenFile.rename(NewName);
            /*Changes the file's label to the value of "NewName" and removes the file type (as the label does not show file type)*/
            ThisFile.Label = NewName.split(".").shift();
            /*Changes the PrintFileName value to the value of "NewName" with the file type changed to ".ps"*/
            ThisFile.PrintFileName = NewName.split(".").shift() + ".ps";
        /*Traverses all files in the books and renames the target the book is looking for. If this is not done, the book will still think the old names exist and will
            try to find them to no avail. "traverse" function sends each component in the book through another function,
              in this case the bookComponentRenamer, and supplies the second function with a parameter, FileArray here.*/
        traverse(BookFile, bookComponentRenamer, FileArray);
        xrefRenamer(FullArray, FileArray);
        /*Saves the book file with the updated component names*/
        BookFile.SimpleSave(BookFile.Name);
        /*When the book is closed, the BookFile variable will no longer function. Assigning the current books name to the "BookName" varibales will allow the book to be reopened*/
        BookName = BookFile.Name;
        /*All open files are closed*/
        closeAll();
        /*Curent book is reopened*/
        BookFile = openBook (BookName);
        /*All book files (now with updated names) are opened*/
        traverse(BookFile, openfile);
        /*Returns the updated book back to the location that originally called the fileNameReplacer function*/
        return BookFile;
    function bookComponentRenamer(Component, FileArray) {
        /*The bookComponentRenamer compares the current book component with names on the FileArray (these are files that have name changes.
            If a match is found, that compent's name is changed within the book itself. This ensures that the names the book file is looking for reflect the updated file names created by this program*/
        for (var i = 0, len = FileArray.length; i < len; i++) {
            if (Component.Name === FileArray[i][1]) {
                Component.Name = FileArray[i][2];
    function xrefRenamer(AllFiles, RenamedFiles) {
        var ThisFile,
            ThisXREF,
            NextXREF,
            OldName,
            NewName,
            XREFTest;
        for (var i = 0, len = AllFiles.length; i < len; i++) {
            /*Assigns the first cross reference in the current file to the "ThisXREF" variable*/
            ThisFile = AllFiles[i][0];
            ThisXREF = ThisFile.FirstXRefInDoc;
            /*Whether "ThisXREF" contains a valid cross reference (having a null value means the file has no cross references, or we have already
                looped through them all and can proceed to the next file in the FileArray)*/
            while (ThisXREF.XRefFile !== null) {
                /*Assigns the next cross reference in the file to the "NextXREF" variable*/
                NextXREF = ThisXREF.NextXRefInDoc;
                /*Loops through all of the files in the FileArray. This will let the current cross reference be compared to the files being renamed and see if
                    there are any matches*/
                for (var j = 0, lenA = RenamedFiles.length; j < lenA; j++) {
                        /*Assigns the old name and the new name of the file being compared to cross references to the "OldName" and "NewName" variables respectively*/
                        OldName = RenamedFiles[j][1];
                        NewName = RenamedFiles[j][2];
                        XREFTest = ThisXREF.XRefFile.indexOf(OldName);
                        /*Tests if the current cross reference being examined links to the current comparison file*/
                        if (0 <= XREFTest) {
                            /*If yes, the cross reference is updated with the new name*/
                            ThisXREF.XRefFile = ThisXREF.XRefFile.replace(OldName, NewName);
                            /*Ends the comparison loop for this cross reference as the correct replacement has been found*/
                            break;
                /*Assigns "ThisXREF" with the value of the "NextXREF" the comparison loop starts again*/
                ThisXREF = NextXREF;
            ThisFile.SimpleSave(ThisFile.Name);

Maybe you are looking for

  • Inserting Rows in an Editable Table

    Application Focus: JSF with ADF/BC. watching Steve Muench´s Screencast on "Creating an Editable Table with a Dropdown List in Each Row" i was inspired to add a functionality to add rows. Lets say i have an Employee and Departments table. If i want to

  • AP Invoices - How to set default Header ?

    Dear All, I want to hide few fields and want to show certain fields in Invoice Entry form. When I go to Folder-Show Field and search for the field The required field get displayed but this activity I need to perform everytime I open the form. Is ther

  • [CS2]Is it possible to use XCode to develop plugin on MAC?

    Hi, Im new to Indesign Plugin Development.Is it possible to use XCode to develop Indesign Plugin on Mac 10.3.9 for Indesign CS2? SDK says that the IDE to be used is Codewarrior 9.3.I have Codewarrior 8.3 installed in my system.Will i be able to compi

  • Migration of cube in Grid

    Hi all, Can we change the data source for the grid in FR?

  • Resizing Browser Window

    Hi, I'm looking to publish my site and have the browser window resize (or stay resized at) the document size (1000x674). I thought i set the proper parameters in DW (i have a SWF inside of it), but there seems to be extra white space on the right sid