[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"

Similar Messages

  • How to rename files by folder name in applescript

    Hi,
    I need to be able to rename files within a folder to the folder name. I have a work flow and script that allows me to find the files within a folder, enter a new file name and starting sequence number in tow seperate dialogue boxes. What I want to be able to achieve is to rename the files without manually entering the name... I still want to be able to manually enter the number.

    Use code such as:
    tell application "Finder"
    set the_folder to (choose folder)
    repeat with this_file from 1 to (count (get files of the_folder))
    set name of file this_file of the_folder to (name of the_folder) & " " & this_file
    end repeat
    end tell
    replacing the last this_file on the fourth line with the variable which contains the number.
    (104354)

  • Renaming files in folder

    trying to figure out how to use automator to rename files within a folder.
    searched on youtube but none of the methods seem to work on my mac.
    if anyone knows of a great tutorial for this i would love to have it.
    thanks'
    Owen

    Sorry, I'm not sure what you mean. Are you referring to the Downloads folder that Mac OS X sets up by default in your user's home directory? If so, you rename files in that folder the same as you would any other folder. The Downloads folder does not (unless something's amiss with the permissions on your system) restrict anything and isn't any sort of "special" folder in terms of how it behaves.
    If that's not what you meant, please post back and explain further.
    Regards.

  • Rename file or folder in Finder?

    I am convert from Windows.
    In Windows, to rename a file or folder you just highlight its icon and hit F2. Then the field becomes editable. Is there such a shortcut key in OS X/Finder? Right now, I am highlighting the file/folder, doing a crtl^ Get Info in the context menu. Really slows me down. Thanks.

    Alternatively, select the file then (after a short delay to avoid double-clicking) click in the name box. This will also make it editable.

  • [Solved] Error : The file or folder path /Probl?me 1 does not exist

    Hello,
    I encountered this error
    The file or folder <path>/Probl?me 2 does not exist
    while I was trying to open a directory already extracted from a zip file containing directories with special characters. In this case, it is a "è" that was misinterpreted as a "?".
    I searched the forums and on google, the solutions proposed do not work for me. Although, I have to deal with these files written in french, I would like to have my locale in english (US), with a system wide support for special characters.
    Attempt 1: Adding the option : iocharset=utf8 into the fstab, like this :
    fstab :
    # /etc/fstab: static file system information
    # <file system> <dir> <type> <options> <dump> <pass>
    none /dev/pts devpts defaults 0 0
    none /dev/shm tmpfs defaults 0 0
    /dev/cdrom /media/cd auto ro,user,noauto,unhide 0 0
    /dev/dvd /media/dvd auto ro,user,noauto,unhide 0 0
    /dev/fd0 /media/fl auto user,noauto 0 0
    /dev/disk/by-uuid/24ba75ac-e52d-40eb-a599-83b394b500b2 /boot ext2 defaults 0 2
    /dev/disk/by-uuid/c797f409-00bc-479a-b4d6-ab49943f644b / ext4 defaults 0 1
    /dev/disk/by-uuid/668427a8-5f51-42bd-a316-fc7984bf5f4f /var ext4 defaults 0 2
    /dev/sda7 swap swap defaults 0 0
    /dev/disk/by-uuid/417cd1b7-8f06-414b-84d5-e8714d9646ab /home ext4 defaults 0 2
    /dev/disk/by-uuid/ef9aa00e-0515-4d7b-aa23-8096e787250d /usr ext4 defaults 0 2
    /dev/disk/by-uuid/17d401b7-2fc7-4d9f-8e17-657d86926d2e /tmp ext4 defaults,iocharset=utf8 0 0 <<<<<<<<<<<<<<
    /dev/disk/by-uuid/71e543b6-e06c-4b0e-b1e3-3b491ff1fefe /var/cache/pacman/repos ext4 defaults 0 2
    #/dev/sda12 /mnt/archive ext4 defaults 0 2
    #.host:/ /mnt/hgfs vmhgfs defaults 0 0
    This solution does not work, because after adding iocharset=utf8, in front or after a "defaults", after a reboot, while mounting the filesystem, there is the following error message:
    Mounting Locale Filesystem :
    mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
    missing codepage or helper program, or other error
    In some cases useful info is found in syslog - try
    dmesg | tail or so
    $ dmesg | tail
    phy0: Selected rate control algorithm 'iwl-agn-rs'
    EXT4-fs (sda5): re-mounted. Opts: (null)
    EXT4-fs (sda5): re-mounted. Opts: (null)
    EXT4-fs (sda6): mounted filesystem with ordered data mode. Opts: (null)
    EXT4-fs (sda8): mounted filesystem with ordered data mode. Opts: (null)
    EXT4-fs (sda9): mounted filesystem with ordered data mode. Opts: (null)
    EXT4-fs (sda10): Unrecognized mount option "iocharset=utf8" or missing value <<<<<<<<<<<<<<
    EXT4-fs (sda11): mounted filesystem with ordered data mode. Opts: (null)
    Adding 2104476k swap on /dev/sda7. Priority:-1 extents:1 across:2104476k
    tg3 0000:07:00.0: irq 44 for MSI/MSI-X
    Attempt 2: Changing all the locale features in KDE and in /etc/rc.conf as well.
    $ vim /etc/rc.conf
    LOCALE="fr_CA.utf8"
    HARDWARECLOCK=""
    TIMEZONE="America/Montreal"
    KEYMAP="us"
    CONSOLEFONT=
    CONSOLEMAP=
    USECOLOR="yes"
    It is complicated to remove these directories. I had to use the inum to get precisely these directories before removing them.
    $ ls -il
    total 8
    1577566 drwxr-xr-x 2 [username] [username] 4096 28 jan 07:09 Probl?me 1
    1577573 drwxr-xr-x 2 [username] [username] 4096 28 jan 07:09 Probl?me 2
    $ find . -inum 1577566 -exec rm -i {} \;
    rm: impossible de supprimer « ./Probl\212me 1 »: est un dossier
    Note that the hypothetical character 'è' is represented has a '\212', a 'È' if seen as a extended ASCII character.
    These directories cannot be deleted this way :
    $ rm -r Problème\ 1
    rm: cannot remove `Problème 1': No such file or directory
    or
    $ rm -r ProblÈme\ 1
    rm: cannot remove `ProblÈme 1': No such file or directory
    What should I do to be make the operating system recognize those special character, and interpret them correctly ?
    Last edited by ramboman (2011-01-29 21:45:50)

    I found a working solution, but better solution are also welcome
    I had to have fr_CA not only in utf8 but also in iso88591. I had to modify the /etc/rc.conf this way :
    LOCALE="fr_CA" <<<<<<<<<<<<<<
    HARDWARECLOCK=""
    TIMEZONE="America/Montreal"
    KEYMAP="us"
    CONSOLEFONT=
    CONSOLEMAP=
    USECOLOR="yes"
    To preserve the english US language system wide, I had to add the following line in the /etc/profile :
    # Allow french special character while in en_US
    export LANG=en_US
    The character misinterpreted by a "?" is now seen :
    as a "è" in dolphin
    as a "?" in the console
    It is now possible to access the folders.

  • Batch rename files that have non consecutive numbers?

    I have a folder with about 100 image files that have non consecutive numbers. Is there a way to rename them all to add something after the numbers (and before file type extension) without changing the numbers?
    Example: If I select 111019.003.dng and 111019.007.dng, is there a way to batch rename to 111019.003_tk.dng and 111019.007_tk.dng?
    Of course, simply batch renaming w/ a sequence number would change them to 111019.003_tk.dng and 111019.004_tk.dng. Which is no good.
    I realize the easiest way around this is to name them correctly the first time, but I am not the photographer.
    Hope this makes sense, and thanks.

    You can bulk rename in Bridge IE:-

  • [SOLVED] Bash: Append file contents to command prompt

    Hi,
    is there a way to append the contents of a file to the command prompt? Say I have defined an alias and I want to change it on the fly. So I'd do
    $ which <my_alias>
    then mark it with the mouse, and paste it to the command line. What I would like to do instead, would be:
    $which <my_alias> > some_temp_file
    $vim some_temp_file #edit the command the way I want it
    $ # somehow get the file contents into the prompt here
    I did try to google it, but to no avail and I know, I could just create a script from some_temp_file but I want the content to appear at the command prompt instead. So is there a way?
    regards,
    mox
    Last edited by Mox (2014-03-07 15:46:09)

    Mox wrote:@progandy: Yes, this might be a step in the right direction. But what do the -i and -v options do? I did not find any documentation in the manpage. And is there a way to expand $COMMAND in the command line before running $COMMAND?
    Why do you want to have the command in a prompt twice? "read -er COMMAND && eval "$COMMAND"" creates a prompt-like environment and then executes the input string. What the options do you can read in the bash-internal help, e.g.:
    $ LC_ALL=C help read
    -e use Readline to obtain the line in an interactive shell
    -i text Use TEXT as the initial text for Readline
    -p prompt output the string PROMPT without a trailing newline before
    attempting to read
    -r do not allow backslashes to escape any characters
    Here is an example:
    [progandy@pamobile ~]$ alias some_test='echo -e Hello WORLD"!"'
    [progandy@pamobile ~]$ command_to_edit="some_test"
    [progandy@pamobile ~]$ read -erp "Edit and execute: " -i "$(command -v $command_to_edit)" COMMAND
    Edit and execute: echo -e Hello WORLD"\t!"
    [progandy@pamobile ~]$ ####### in the line above you edit the command and bring it in the final form with all necessary paramters.
    [progandy@pamobile ~]$ echo -E " *~* Now running: $COMMAND"
    *~* Now running: echo -e Hello WORLD"\t!"
    [progandy@pamobile ~]$ eval "$COMMAND"
    Hello WORLD !
    [progandy@pamobile ~]$
    Last edited by progandy (2014-03-05 05:21:39)

  • Mass rename of every photo and sequential numbering of every future download

    Is it possible to have iphoto 9.6 mass rename every single photo I have sequentially so there are no duplicate file names and then pull in every new photo no matter the source with sequential file names so there is never a duplicate?

    no
    iPhoto makes no changes of any sort when it imports - you can rename the files when you export but not when miporting or while photos are in iPhoto
    for export options see Exporting From iPhoto
    LN

  • Can't delete, rename files, or move to another folder

    I had posted earlier about not being able to delete, rename files, or move to another folder. It never was resolved here, and I guess Apple still hasn't done anything about it. Here's a great workaround I found though in case others need something. Download the program called "Unlocker", it's free and you can get it at http://ccollomb.free.fr/unlocker/ When you get the message about the file being in use, even though QuickTime isn't even open, you can unlock the f'ing file and do whatever you want to then, move, uh DELETE, or rename, or whatever. Try it, it's the best thing going so far seeing Apple isn't doing anything about this problem.

    Hi there,
    I am still struggling with this problem. Actually my coworker has the same machine, Apple pro with windows xp installed, but he does not have this problem with his quicktime 7.5. I uninstalled 7.5 and installed 7.2, but it did not solve the problem. The fact is that I don't have the problem in my laptop which I am using it in the office. I am still trouble shooting. Hopefully I can find an answer.
    Peace

  • [solved]bash help please: sort files & recognize duplicates

    Hi!
    I'm trying to move/rename all files in a folder and its subfolder by age.  And move duplicate files somewhere else. The output looks mostly fine, the tmp files too... but I can't figure out, why the duplicate files handling isn't working. edit: the line that sets the new name (&& newname="$1/.dupes/$dname/$part1_$part2_$fname" \) just doesn't seem to get executed here...
    #!/bin/bash
    pushd "$1" && {
    rafi="/tmp/$RANDOM.size.md5.list" && echo > "$rafi"
    find $1 -type f -print0 | while read -d $'\0' file;
    do \
    fname=$(basename "$file")
    dname=$(dirname "$file")
    part1=$(stat -c%y "$file" | awk -F " |:|\\\.|-" '{printf $1"-"$2"-"$3}')
    part2=$(stat -c%y "$file" | awk -F " |:|\\\.|-" '{printf $4"-"$5"-"$6}')
    echo "$bname" | grep -q "$part1" && part1=""
    echo "$bname" | grep -q "$part2" && part2=""
    newname="$1/$part1/$part2_$fname"
    size="size$(stat -c%s "$file")"
    grep -q "$size" "$rafi" \
    md5="md5$(md5sum -b "$file" | sed "s/ .*//")"
    grep -q "$md5" "$rafi" \
    && newname="$1/.dupes/$dname/$part1_$part2_$fname" \
    || {
    echo "$md5" >> "$rafi"
    } || {
    echo "$size" >> "$rafi"
    newname=$(echo "$newname" | sed "s/\/\/*/\//g" | sed "s/\.~.~//g")
    if [ "$newname" != "$file" ];
    then if ! [ -d $(dirname "$newname") ]
    then echo mkdir -p $(dirname "$newname") -v
    fi
    echo mv "$file" "$newname" -v --backup=numbered
    fi
    done
    popd
    What am I doing wrong? Been trying for hours - I just don't get it...
    Thanks!
    Last edited by whoops (2011-03-01 10:19:48)

    thx, that brought me a little closer!
    juster wrote:I don't usually say this for bash but your style is hard to read.
    Oops... thought so - never had an easy time writing readable code. Or readable anything... Maybe this is not as bad:
    #!/bin/bash
    if pushd "$1"
    then
    # random tmp file for filesize + md5
    rafi="/tmp/$RANDOM.size.md5.list" && echo > "$rafi"
    # for all files in folder $1 + subfolders...
    find $1 -type f -print0 | while read -d $'\0' file
    do
    fname=$(basename "$file")
    dname=$(dirname "$file")
    # Get year-month-day
    part1=$(stat -c%y "$file" | awk -F " |:|\\\.|-" '{printf $1"-"$2"-"$3}')
    # Get hour-minute-second
    part2=$(stat -c%y "$file" | awk -F " |:|\\\.|-" '{printf $4"-"$5"-"$6}')
    # Don't add this info to new filename if it is already in old filename
    echo "$bname" | grep -q "$part1" && part1=""
    echo "$bname" | grep -q "$part2" && part2=""
    # Destination filename
    newname="$1/$part1/${part2}_$fname"
    size="size$(stat -c%s "$file")"
    # have files with the same size already been processed?
    if grep -q $size "$rafi"
    then
    md5="md5$(md5sum -b "$file" | sed "s/ .*//")"
    # have files with the same md5 already been processed?
    if grep -q $md5 "$rafi"
    # set different destination for duplicate files
    then newname="$1/.dupes/$dname/${part1}_${part2}_$fname"
    # write md5 to tmp file
    else echo $md5 >> "$rafi"
    fi
    # write size to tmp file
    else echo "$size" >> "$rafi"
    fi
    # remove double slashes
    newname=$(echo "$newname" | sed "s/\/\/*/\//g" | sed "s/\.~.~//g")
    if [ "$newname" != "$file" ]
    then if ! [ -d $(dirname "$newname") ]
    then echo mkdir -p $(dirname "$newname") -v
    fi
    echo mv "$file" "$newname" -v --backup=numbered
    fi
    done
    popd
    fi
    Renaming seems to work correctly now, but it's still only giving me one "dupe mv line" for my test in /etc/X11 and it's not giving me any for the many duplicates in my huge digicam folder.
    $ sort_by_date /etc/X11/
    ~
    mkdir -p /etc/X11/2011-02-27 -v
    mv /etc/X11/xorg.conf.bak /etc/X11/2011-02-27/19-43-36_xorg.conf.bak -v --backup=numbered
    mkdir -p /etc/X11/2010-06-21 -v
    mv /etc/X11/xorg.conf.d/20-nvidia.conf /etc/X11/2010-06-21/10-12-35_20-nvidia.conf -v --backup=numbered
    mkdir -p /etc/X11/2010-08-24 -v
    mv /etc/X11/xorg.conf.d/10-evdev.conf /etc/X11/2010-08-24/15-45-35_10-evdev.conf -v --backup=numbered
    mkdir -p /etc/X11/2010-09-01 -v
    mv /etc/X11/xorg.conf.d/20-nvidia.conf.pacnew /etc/X11/2010-09-01/12-16-10_20-nvidia.conf.pacnew -v --backup=numbered
    mkdir -p /etc/X11/2010-11-30 -v
    mv /etc/X11/xorg.conf.d/20-keyboard.conf /etc/X11/2010-11-30/10-27-00_20-keyboard.conf -v --backup=numbered
    mkdir -p /etc/X11/2010-05-26 -v
    mv /etc/X11/xorg.conf.d/10-quirks.conf /etc/X11/2010-05-26/21-51-03_10-quirks.conf -v --backup=numbered
    mkdir -p /etc/X11/2010-01-03 -v
    mv /etc/X11/xorg.conf /etc/X11/2010-01-03/10-56-25_xorg.conf -v --backup=numbered
    mkdir -p /etc/X11/.dupes/etc/X11 -v
    mv /etc/X11/xorg.conf.dub /etc/X11/.dupes/etc/X11/2011-02-27_19-43-52_xorg.conf.dub -v --backup=numbered
    mkdir -p /etc/X11/2010-07-10 -v
    mv /etc/X11/Xsession /etc/X11/2010-07-10/20-01-30_Xsession -v --backup=numbered
    mkdir -p /etc/X11/2010-12-22 -v
    mv /etc/X11/xinit/xinitrc.d/30-dbus /etc/X11/2010-12-22/15-39-41_30-dbus -v --backup=numbered
    mkdir -p /etc/X11/2010-11-28 -v
    mv /etc/X11/xinit/xinitrc.d/40-libcanberra-gtk-module /etc/X11/2010-11-28/02-44-08_40-libcanberra-gtk-module -v --backup=numbered
    mkdir -p /etc/X11/2010-12-19 -v
    mv /etc/X11/xinit/xserverrc /etc/X11/2010-12-19/11-58-47_xserverrc -v --backup=numbered
    mkdir -p /etc/X11/2010-11-15 -v
    mv /etc/X11/xinit/xinitrc /etc/X11/2010-11-15/11-39-17_xinitrc -v --backup=numbered
    ~
    Still don't get it where this problem could be coming from...
    md5sum * 2>/dev/null | sort -k 1 | uniq -d -w 32 | cut -c 35-
    That's beautiful, just I have no idea how to use it in the context of what I'm trying to do.
    Last edited by whoops (2011-02-28 13:00:27)

  • SOLVED: The file or folder is corrupted and unreadable.

    On a Windows 7 Pro workstation, whenever a user logs in, they receive an error that the file C:\Windows\System32\en-us\winlogon.exe.mui is missing or corrupted. Every normal restart of Windows automatically invokes chkdsk c: /f. I've tried the
    following:
    Run chkdsk c: /f /r. The first run found several soft problems, but no physical problems with the drive. A subsequent run found no problems.
    Checking the memory. A bad stick was found and replaced. A re-run of the memory diagnostic with the new memory returns no errors. I believe that the problem was caused by the bad memory.
    Run sfc /scannow. The CBS.log reveals that there are problems that can't be fixed.
    An upgrade re-installation of the OS. It fails saying that there are problems on the disk.
    Upon investigation, the file winlogon.exe.mui is missing, but there is now a subfolder by that name in C:\Windows\System32\en-us. That folder is not normal and, as far as I know, shouldn't exist. The folder cannot be deleted or renamed. All attempts to do
    so fail with an error that "the file or folder is corrupt". Attempts to copy the file obtained from another computer also fail with the same error.
    Every normal restart of Windows automatically invokes chkdsk c: /f, but no errors are reported. I've even tried booting from a USB-based OS and running chkdsk on the drive, but no errors are reported, although the error persists.
    Before I reformat the drive and start from scratch (it's a custom workstation that will take more than a day to rebuild), I thought I'd ask if anyone has any ideas about what I can do. I'll be grateful for any suggestions.

    Hi David,
    Thank you for sharing your solutions and experience here. It will be very beneficial for other community members who have similar questions.
    Karen Hu
    TechNet Community Support

  • Weird flashing problem - cannot rename any file or folder in Movies

    I have a problem affecting just my Movies folder. Whenever I view it in the Finder, the edge of the Finder window will flash once every four seconds. If I am trying to rename an item within the Movies folder when the flash happens, I get dumped out of the name editor and the file or folder is given the partially-typed name.
    It only happens when I'm viewing the Movies folder in the Finder. Any ideas?
    Message was edited by: Gareth Randall2

    What do you mean by "flashing"? Can you post a video or photos for us to see?

  • How to rename a file or folder.

    HI, I was thinking of some thing, but I need to know how to make java rename a file/folder like you do via dos.
    Hope this is clear.
    PS I had another post and I got the answer thanks for those who help, I lost the thing so couldn't reply(DUH').
    So say I have "myfile.txt", and wanna rename to "yourfile.txt".
    Just point my in the right direction if it's long.

    import java.io.*;
    public class Rename
         public static void main (String args [])
         { // main program
    // File (or directory) with old name
    file f1 = new File("newone.txt");
    // File (or directory) with new name
    File f2 = new File("newfile.txt");
    // Rename file (or directory)
    boolean success = f1.renameTo(f2);
    if (!success)
    // File was not successfully renamed
    System.out.println("\nFile was renamed!\n\n");
    This is what I have done, the import removed 3 of the 4 errors, but its still not working, this is the message.
    C:\Documents and Settings\jonathan\Desktop\New Folder (2)\Rename.java:7: cannot resolve symbol
    symbol: class file
    location class rename
    file f1 = new file("newone.txt")
    ^
    1 error

  • Need a script to do the following... rename files based on folder name...

    Hi. Macophile just starting to tread the waters of Applescript, trying to use Automator but don't think it will do what I need.
    I have many images stored with-in folders that I would like to extrapolate a given number of characters from the folder name and Add Text to the files within those given folders.
    Basically...
    Folder name is C00100_Descriptive
    Files within folder are just Descriptive_01, Descriptive_02
    Would like to make all files within a given folder take the first 7 characters from the folder and Add that text to all files and files within subfolders of that folder to make the resulting files shown as...
    C00100Descriptive01
    C00100Descriptive02
    Along with this I would also like to incorporate into the script, an added step to create Thumbnail jpegs of the image files in a Subfolder under C00100_Descriptive folder.
    I can see how to do that in automator but not specifying parameters such as taking a certain number of characters from the folder the file resides in and adding that selected text to the files.
    Ideally I would like a droplet or something that I could take a bunch of folders and drop them on the droplet to perform these actions.
    Any advice, help or guidance would be really helpful! Thanks in advance.

    Awesome, you're quite welcome, glad to hear it worked for ya!! Here's another version of the script that will rename the thumb files as jpg...
    <pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
    title="Copy this code and paste it into your Script Editor application.">on run
    set theItems to choose folder with multiple selections allowed
    open (theItems)
    end run
    on open (itemList)
    repeat with anItem in itemList
    set theInfo to info for anItem
    --VERIFY THAT THE OPENED ITEM IS A FOLDER
    if folder of theInfo and not package folder of theInfo then
    --SET PATH TO THE FOLDER
    set theFolder to POSIX path of anItem
    --GET FIRST PART OF FOLDER NAME
    set folderNameStart to do shell script "echo " & ¬
    quoted form of (name of theInfo) & "|awk -F'_' '{print $1}'"
    --GET ALL FILE NAMES
    set fileList to list folder anItem without invisibles
    --PROCEED IF FOLDER NOT EMPTY
    if fileList is not {} then
    --SET PATH TO THUMBNAIL FOLDER
    set thumbFolder to theFolder & "_thumbs/"
    --CREATE FOLDER IF IT DOESN'T ALREADY EXIST
    try
    do shell script "mkdir " & quoted form of thumbFolder
    end try
    --PROCESS FILES
    repeat with fileName in fileList
    --SET PATH TO CURRENT FILE
    set oldFile to theFolder & fileName
    --PROCEED IF FILE IS NOT A FOLDER
    set oldFileInfo to info for POSIX file oldFile
    if not folder of oldFileInfo then
    --SET NEW FILE AND THUMB FILE PATHS
    set newFileName to folderNameStart & "_" & fileName
    set newFile to theFolder & newFileName
    set theExt to name extension of oldFileInfo
    set thumbName to text 1 through -((length of theExt) + 1) of newFileName & "jpg"
    set thumbFile to thumbFolder & "thumb_" & thumbName
    --RENAME FILE
    do shell script "mv " & quoted form of oldFile & space & ¬
    quoted form of newFile
    --CREATE THUMBNAIL
    --REPLACE '128' WITH MAX HEIGHT OR WIDTH OF THUMB
    try
    do shell script "sips -s format jpeg -s dpiHeight 72 -s dpiWidth 72 -Z 128 " & ¬
    quoted form of newFile & " --out " & quoted form of thumbFile
    end try
    end if
    end repeat
    end if
    end if
    end repeat
    end open</pre>

  • Possible: renaming files - folder names as variables.

    Here's a bit of background - I have a rather extensive MP3 collection (all legal - I work for an independent music magazine in my spare time) - it's approx 7,000 files big now.
    I have them all stored in folders as follows:
    c:\SAMag\MP3's\Albums (and here comes the tricky bit...)
    EITHER
    \Artist Name Here - Album Title\<.MP3 files here> (No artist names contain a '-' so this is the seperator)
    OR
    \Artists Name Here\Albums Title One\<.MP3 files here>
    \Artists Name Here\Albums Title Two\<.MP3 files here>
    \Artists Name Here\Albums Title Three\<.MP3 files here> (Where there are more than one albums to an artist)
    Playing these files is a nightmare as they all have different naming conventions and odd ID tags. I want to remove all ID tags and rename them to have meaningful file names (so that WinAmp displays a decent, non-confusing, name).
    I would like:
    "<artist name> - <song title> (<album title> - <#>)"
    So, basically - is it possible to rename files in Java. Specifically: using the folder names that they are contained in as variables to put in this name?
    Thanks for any help people!

    Thanks for that.
    I'm pretty new to this whole Java thing (even though
    I've been attempting to do it for a while!) so was
    wondering if you could point me in the right
    direction.
    That is exactly what I did though.
    Do you have the javadocs? If so then you look up java.io.File and read the methods in it.
    Here is the online link....
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

Maybe you are looking for

  • Getting my mail after moving to icloud

    Hi. I have a 10.6.8 operating system. I can not retrieve mail from my usual [email protected] Every time I want to see my mail, I have to go to the MobileMe ending notifcation notice, sign in, and see my mail on icloud. I don't want to do this every

  • Using a SSD?

    Has anybody installed and run an SSD in their PB? Were there any problems?

  • Why am I seeing this:  Built-in Input by Apple Inc. is overloaded!!!

    I see this message in the console every 3 minutes and sometimes 3 times in a row (individual messages) and last message repeated 3 times: 2/24/08 3:34:39 PM [0x0-0x18018].com.apple.dock[185] 2008-02-24 15:34:39.208 DashboardClient[2614:ad0b] * Audio

  • OS level script

    Hi I am facing an issue , i am unable to schedule OS level scripts from SAP. Can anyone let me know if there is a function module through which i can trigger a Solaris OS level script. Many thanks in advance for youe help. Deb Sircar

  • F4 help on variable screen only shows text or key...not both

    In some queries, the F4 help will only show text oy key but not both. For example, the F4 help on 0employee only gives a list of personnel numbers. The search in the dialog box only works for the pernrs and we can't search for names.This is happening