Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is it possible to automate the following action:

Example

Folder name: "TEST" the name of the file inside the folder is: "Evelyn.jpg".

How do I rename the folder using the name of the file inside of it:

Result

Folder name: "EVELYN" the name of the file inside the folder is: "Evelyn.jpg".

Any ideas how to achieve this with Automator or AppleScript?

share|improve this question
    
The folders each contain a single file? –  Daniel Lawson Nov 8 '11 at 22:38
add comment

2 Answers 2

Here's a script:

set thefolder to "path:to:folder" as alias
tell application "Finder"
    set filename to name of first item of folder thefolder
    set oldDels to AppleScript's text item delimiters as string
    set AppleScript's text item delimiters to "." as string
    set itemname to first text item of filename
    set AppleScript's text item delimiters to oldDels as string
    set name of thefolder to itemname
end tell

It gets the name of the first item in the folder, clips off the extension, and renames the folder.

Note that it doesn't convert to uppercase as in your example. This is less than trivial with AppleScript, but let me know if it's real important and I can give you the code.

share|improve this answer
    
And yeah, I know about displayed name, but that can include the extension (depending on the user's configuration). –  Nathan Greenstein May 24 '11 at 23:40
    
Thanks a bunch mate. –  Liviu May 25 '11 at 19:00
    
The script works fine like this, but what if I have a 100 folders? –  Liviu May 25 '11 at 19:05
    
@Liviu Unless the 100 are in the same place, you'll have to do this to each of them. But, if each of the folders is in the same place (/Users/bob/Desktop/Folder1, /Users/bob/Desktop/Folder2, etc), we can automate it. Let me know whether or not all the folders are in the same place. –  Nathan Greenstein May 28 '11 at 16:21
add comment

Here is an Automator Workflow that will do it for you.

enter image description here

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.