I’m looking for a way to get a containing folder name into each filename inside it.
IE., a file named “file” inside a folder named “folder” would be renamed “folder file”.
I have a lot of files that are inside folders with the dates and would like to add those dates to file names, but haven’t been able to figure it out yet.
I thought I might be able to use the container as string, but haven’t been able to make it work from scraps of scripts.
Any help would be greatly appreciated.
Thanks,
Chris
If I understand the question correctly:
tell application "Finder"
set baseFolder to (choose folder) -- get the folder
set baseFolderName to name of baseFolder as text -- work out its name
repeat with eachFile in (files of folder baseFolder) -- iterate through the files in this folder
set name of eachFile to (baseFolderName & name of eachFile) -- rename each file
end repeat
end tell
That looks like exactly what I want to do but it doesn’t seem to want to work when I save it out as an application on a 10.4.1 and 10.3.9 machine. It starts and gets the folder name but doesn’t seem to want to apply it to the file names.
As a side question, is there any character limit to new filenames?
Thanks again Camelot,
Chris
Have you considered using a shell script? The UNIX script is very simple:
do shell script "mv " & eachFile & " " & (baseFolderName & name of eachFile)
This would replace the line inside of the repeat and rename all the files.
Good Luck
Craig Smith