Hi there,
I am writing a script to resize and rename images from a CD with lots of folders and subfolders. I have a script that will do it for one folder, but not the subfolders of that master folder. I have an if statement that gives me a list of the subfolders but when I try to process each of those subfolders I am not able to refer to items of the subfolders. Hopefully this makes sense to someone.
thanks for any help
--separate folders from other loose files, add to list sub_folders
global sourcefolder
set sourcefolder to "Macintosh HD:Users:iMac_G5:Desktop:asource_folder:"
set infofile to (info for file "Macintosh HD:Users:iMac_G5:Desktop:asource_folder:")
global holding_folder
set holding_folder to "Macintosh HD:Users:iMac_G5:Desktop:aholding_folder:"
global sub_folders
set sub_folders to {}
set filelist to list folder sourcefolder without invisibles
repeat with i from 1 to number of items in filelist
set this_item to item i of filelist
set inforec to info for file (sourcefolder & this_item)
if (kind of inforec) is "folder" then set end of sub_folders to (name of inforec)
end repeat
end
if exists items in sub_folders then renamestuff()
AppleScript: 1.9.3
Browser: Safari 125.11
Operating System: Mac OS X (10.4)
Here are a couple of ways to get all the files (including ones in subfolders) into a list:
property sourceFolder : alias "Macintosh HD:Users:iMac_G5:Desktop:asource_folder:"
tell application "Finder"
launch
set allFiles to (files of entire contents of sourceFolder whose name extension is "jpg") as alias list
end tell
repeat with thisFile in allFiles
--whatever else
end repeat
property sourceFolder : "/Users/iMac_G5/Desktop/asource_folder"
do shell script "/usr/bin/find " & quoted form of sourceFolder & " -iname \\*.jpg"
set allFiles to paragraphs of result
repeat with thisFile in allFiles
set thisFile to POSIX file thisFile
--whatever else
end repeat
Hi Bruce,
thanks for the quick reply. I should have better explained myself though, what I want to do is reaname the jpgs in a particular folder with the name of the folder that they are in. So I want the script to go through a folder, set the name of the subfolder to newname and then proceed to rename each item in the subfolder. I can get a list of subfolders but I can’t get the name of the subfolder and I can’t get to the items of the subfolder. Maybe I am going about this the wrong way, I thought in order to get the name of files or folders I need to set a variable to the ‘info for file’ of that file. I think I am losing it.
Anyway thanks again,
Jamie
Do you want to number the files, just add the folder’s name to the beginning of the filename, or something else?
I wanted to change the name of the jpeg to the name of the subfolder from which it originates and add a +1 each time. I can get a list of subfolders but it’s class is a ‘list’ and it doesn’t seem to have any other useful information for the rest of the script, like name of path.
What do you think?