You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

Error in Applescript to create named subfolders

Hello,


i'm trying to make a script that creates subfolders for every subfolder of the location you choose, with modified names.


Basically:

  • I have Folder/subfolder1, Folder/subfolder2,...
  • The script should create Folder/subfolder1/2020_subfolder1, Folder/subfolder2/2020_subfolder2 and so on and so forth


The current error:

"Finder got an error: Can’t get path of folder "test" of folder "Desktop" of folder "johndoe" of folder "Users" of startup disk." - happens on

set myFolderlocation to path of aFolder


Here's my current full code from script editor:


--on run

set theFolder to (choose folder with prompt "Select the folder")

doSomethingWith(theFolder)

--end run


on doSomethingWith(aFolder)
	
	tell application "Finder"
		
		set subFolders to every folder of aFolder
		
		repeat with eachFolder in subFolders
			
			set myFolderlocation to path of aFolder
			my doSomethingWith(eachFolder)
			
		end repeat
		
	end tell
	
	--create the name "2020_NameofParentfolder"; this could be simplified
	set myParentFolderName to name of aFolder
	set mywhataname to ("2020_" & myParentFolderName) as text
	
	--creates the subfolder, with the adapted name i've set before
	make new folder at myFolderlocation with properties {name:mywhataname}
	
end doSomethingWith


Note: I took part of the code from "Iterating through folders" because i don't know applescript too well. https://discussions.apple.com/thread/2716678


I appreciate any help, already spent two or three hours researching but even that's hard with my very low konwledge of applescript.

Posted on Jan 8, 2021 4:42 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 8, 2021 11:38 AM

> set myFolderlocation to path of aFolder


nix the 'path of'...


For one, path is not a valid property of an alias (which is what choose folder returns).

For two, it isn't necessary. You can just pass aFolder to the Finder's make new folder command. There is no need to coerce it to a path.

For three, if you did ever need to coerce an alias to a path, just ask for it as text:


set theFolder to (choose folder with prompt "Select the folder")
set theFolderPath to theFolder as text



Similar questions

1 reply
Question marked as Top-ranking reply

Jan 8, 2021 11:38 AM in response to DennisRadioman

> set myFolderlocation to path of aFolder


nix the 'path of'...


For one, path is not a valid property of an alias (which is what choose folder returns).

For two, it isn't necessary. You can just pass aFolder to the Finder's make new folder command. There is no need to coerce it to a path.

For three, if you did ever need to coerce an alias to a path, just ask for it as text:


set theFolder to (choose folder with prompt "Select the folder")
set theFolderPath to theFolder as text



Error in Applescript to create named subfolders

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