Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

I'm stuck setting file metadata from parent folder name

Hi everyone


I really hope someone can help me, I’ve been going around in circles on this. I’d like to rename all the album name metadata in my music collection, setting it to the parent folder name. The iteration that I think is needed is:


for each folder

for each file

store folder name as string

set file metadata = subfolder string

end

end


So far I've managed to iterate through subfolders, but just accessing the files of the folder is where I'm stuck. Because I have album year often prefixing the album name, I get an error because it thinks it's an integer. (after this I'll still need to change that filename's metadata, which I'm not at all sure of either)...



on run

set ArtistFolder to (choose folder with prompt "Select the start folder")

RenameMetadata(ArtistFolder)

end run


on RenameMetadata(aFolder)

tell application "Finder"

set subFolders to every folder of aFolder

repeat with eachFolder in subFolders

my RenameMetadata(eachFolder)

set theItems to every file of folder (eachFolder)

repeat with theFile in theItems

set firstString to name of theFile

log FileName

end repeat

end repeat

end tell

end RenameMetadata

latest OS (10.10)

Posted on Nov 18, 2015 9:59 AM

Reply
Question marked as Best reply

Posted on Nov 18, 2015 3:01 PM

pjt1977 wrote:


So far I've managed to iterate through subfolders, but just accessing the files of the folder is where I'm stuck. Because I have album year often prefixing the album name, I get an error because it thinks it's an integer. (after this I'll still need to change that filename's metadata, which I'm not at all sure of either)...


Try using: as string:

set firstString to name of theFile as string

6 replies
Question marked as Best reply

Nov 18, 2015 3:01 PM in response to pjt1977

pjt1977 wrote:


So far I've managed to iterate through subfolders, but just accessing the files of the folder is where I'm stuck. Because I have album year often prefixing the album name, I get an error because it thinks it's an integer. (after this I'll still need to change that filename's metadata, which I'm not at all sure of either)...


Try using: as string:

set firstString to name of theFile as string

Nov 18, 2015 12:26 PM in response to pjt1977

tell application "Finder" to set foldname to name of (parent of pf)


Where pf is a file within the current folder. If the file is on the Desktop, this will just return "Desktop" .


tell application "Finder" to set foldname to URL of (parent of pf) as POSIX file


will return the full HFS path to the parent folder.


tell application "Finder" to set foldname to POSIX path of (URL of (parent of pf) as POSIX file)


will return the full POSIX path to the parent folder.

Nov 20, 2015 5:14 AM in response to VikingOSX

thanks for that.


I'm afraid I don't understand how to get this working after so much time and effort, and helpful suggestions - thanks so much everyone. It seems a shame that I can now iterate through every folder and hold the name of the parent folder in a string but still not manage to get that string into the ID3 album name tag. I'll have to keep coming back to it when I have a spare moment (unless someone can help me)...



on run

set ArtistFolder to (choose folder with prompt "Select the start folder")

RenameMetadata(ArtistFolder)

end run



on RenameMetadata(aFolder)

tell application "Finder"

set subFolders to every folder of aFolder

repeat with eachFolder in subFolders

my RenameMetadata(eachFolder)

set theItems to every file of eachFolder

repeat with theFile in theItems

set strParent to name of eachFolder as string

set strFile to name of theFile as string


(* ? set ID3 album name tag to strParent *)


end repeat

end repeat

end tell

end RenameMetadata

I'm stuck setting file metadata from parent folder name

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.