1/19/11
10:46 am

Forum Question: Rename folder using the name of the file inside the folder Automator action

Trying to rename a bunch of folders with the name of images inside the folder with automator.
EXAMPLE:
Before Action>
Folder Name: 2008photo
Name of the file inside this folder: design12
After Action>
Folder Name: design12
Name of the file inside this folder: design12
Any help would be greatly appreciated. Now get behind the mule and plow.
—–
Liviu Ignat

Comments: 5 Responses to “Rename folder using the name of the file inside the folder Automator action”

    1/19/11 @ 10:49 am

    That’s an interesting one. I suppose it can be done.
    But how many folders do you have like this?
    If there are thousands, then sure. But a few dozen or even a hundred it might be worth it to do it manually or find another way to organize.

    1/19/11 @ 11:10 am

    Ah, I see. There are other files there too. OK.
    I would say that this is better suited for Terminal and the command line than for Automator. Command line is great for renaming files. But, how to pick up a filename inside a folder and then use that for the rename?
    I’m not sure. I’ll tweet this and see if any command line experts can help.

    Michael
    1/19/11 @ 11:25 am

    ls */*.jpg | sed ‘s,\([^/]*\)/\(.*\).jpg,echo mv “\1” “\2”,’ | sh

    Then when it looks good, remove the “echo “

      Michael
      1/19/11 @ 11:58 am

      And if that gives you too many filenames, you can do this:

      find * -name \*.jpg -print | sed …

      Note on that: resist the temptation to do “find .” but if you’re still getting too many filenames, you can do:

      find . -name \*.jpg -print | sed ‘s,\./\([^/]*\)/\(.*\).jpg,echo mv “\1” “\2”,’ | sh

      Also note that the quotes there are all ASCII double quotes or single quotes (unshifted double quotes)

      And when you like the output, change it to:

      find . -name \*.jpg -print | sed ‘s,\./\([^/]*\)/\(.*\).jpg,mv “\1” “\2”,’ | sh

Comments Closed.