Jump to content

[SOLVED] Rename file using its parent directory name???


Recommended Posts

Posted

Hi All,

Just found out about the app Alfred while searching automation options.
I am hoping the community can shed some light on whether Alfred can help me or not and if yes, give me a steer in the right direction.

 

What I would like to do is:
1-Rename an mp3 file, preserving its extension, using its parent, sub-directory name.
2-Move the file to the root directory and delete the original parent directory.

 

For example, change this:
Songs (Root directory)
    Good song (sub-directory)
        asdfgh.mp3 (file)
    Really good song (sub-directory)
        zxczvb.mp3 (file)

 

To this:
Songs (Root directory)
    Good song.mp3 (renamed & moved file)
    Really good song.mp3 (renamed & moved file)
    

Many thanks,
Sim871

Posted

Welcome @sim871,

 

Yes, that is quite possible, though not without coding. Also, you need to buy Alfred’s PowerPack. If you do so, I can make the workflow for you. It’ll work like this:

  1. You select the file.

  2. Press a keyword. A menu will appear.

  3. You pick the relevant action.

  4. Done.

Posted

Hi Vitor,

Thanks for the speedy reply. I purchased the power pack. Grateful for any help!

For clarity, I was hoping to point Alfred to the Songs (Root directory) and have it run the script/macro against all of the sub-folders in the the Songs (Root directory).

Is this possible?

 

Songs (Root directory)
    Good song (sub-directory)
        asdfgh.mp3 (file)
    Really good song (sub-directory)
        zxczvb.mp3 (file)

 

To this:
Songs (Root directory)
    Good song.mp3 (renamed & moved file)
    Really good song.mp3 (renamed & moved file)

Posted

This should work.

 

It only works on .mp3 files, but it does work recursively (it moves everything to the top directory).

 

Do note as a warning that since its operations are destructive (it renames the file and deletes the directory) you should back up your data before running the Workflow, just in case. For example, if a directory has two .mp3 files, since both will be moved to the top directory with the same name, one of them would be lost.

 

To run this, select your Songs directory (can be any name) and run the Rename Songs File Action.

Posted
17 hours ago, sim871 said:

All I can say is MAGIC! And thank you.

Works amazing.

 

You’re welcome. I’m glad.

 

17 hours ago, sim871 said:

What language is the script written in?

 

Ruby, but any general purpose language would’ve worked.

  • vitor changed the title to [SOLVED] Rename file using its parent directory name???

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...