Check for existing folders

Hello All,
I was wondering if someone could help me here. I am working on a script that creates new folders from returned dialog box text. I would like the script to check for the existence of same named folders so that options can be given rather than the script editor finding dupes and showing an error. Thanks for any advice, Dan

Hi Dan,

Will the input from the dialog be a complete path to a folder or just a name? Do you have a script to post so that we can see how it all comes together? :slight_smile:

The rough script looks like this:
tell application “Finder”
activate
set target_folder to choose folder with prompt “Select a Destination.”
display dialog “Create a New Folder” default answer " " with icon 1
set new_job to result
–repeat or repeat while
if new_job of target_folder exists then
display dialog “A Folder with that name already exists in this location” default answer “” with icon 0
set new_job to result
make new folder in target_folder with properties {name:text returned of new_job}
–and then a miracle happens
else
make new folder in target_folder with properties {name:text returned of new_job}
end if
–end repeat
end tell

Does this do what you want?

set folderExists to true

tell application "Finder"
	activate
	set target_folder to choose folder with prompt "Select a Destination."
	display dialog "Create a New Folder" default answer " " with icon 1
	set new_job to text returned of the result
	
	repeat until folderExists is false
		set folderExists to exists folder new_job of target_folder
		if folderExists is true then
			display dialog "A Folder with that name already exists in this location" default answer "" with icon 0
			set new_job to text returned of the result
			set folderExists to exists folder new_job of target_folder
		end if
	end repeat
	
	make new folder in target_folder with properties {name:new_job}
end tell

Yes Rob, that does it exactly - and thank you! -Dan