Need Help Renaming a file to the name of the enclosing folder

I’m trying to figure out how to make a droplet that I can drop a folder (or bunch of folders) onto and it will rename the enclosed file to the same name as folder.

Example Folder “TV SHOW NAME BLAH” with a file named “something totally wrong.mkv” inside would result the file being renamed to “TV SHOW NAME BLAH.mkv”

Looked at a couple of scripts that were sorta similar via search, but could not get them to work the way I need them to.

TIA if you can help!
:smiley:

Hi,

try this


oon open theseItems
	repeat with anItem in theseItems
		set {name:folderName, folder:isFolder, package folder:isPackage} to info for anItem
		if isFolder and not isPackage then
			try
				tell application "Finder"
					set theFile to file 1 of anItem
					set fileExtension to name extension of theFile
					if fileExtension is missing value then
						set newFileName to folderName
					else
						set newFileName to folderName & "." & fileExtension
					end if
					set name of theFile to newFileName
				end tell
			end try
		end if
	end repeat
end open


Worked Perfectly! :smiley:

Thanks very much for the help!