[REQ] Make Surrounding Folder for several files

Hi!

I’ve been trying to make a script to do this, but the minute I “fix” something, something else breaks…

I have a folder with several files inside and I need to create a surrounding folder for each of the files, naming each folder as the file it contains, minus the extension. This is what I mean:

I have the original folder with several items inside:
Location/FolderA {item1, item2, item3, …, itemX}

And I need to end up with:
Location/Folder1/Item1
Location/Folder2/Item2
Location/Folder3/Item3, …,
Location/FolderX/ItemX

where Location is the path to the original folder and each of the created folders is named after the item it contains. What I have so far doesn’t even come close to accomplishing this, so I think it’d be confusing to even post it here.

I’d be nice if this could be a droplet, so I’d just take the original folder and drop it onto the script.

Thanks in advance to anyone that can help!

Rick.

Hi,

try this


property baseFolder : missing value

on run
	set baseFolder to choose folder with prompt "Choose base folder"
	tell application "Finder" to set theFiles to files of baseFolder as alias list
	open theFiles
end run

on open theItems
	if baseFolder is missing value then set baseFolder to choose folder with prompt "Choose base folder"
	repeat with oneItem in theItems
		set {name:Nm, name extension:Ex} to (info for oneItem)
		copy Nm to fileName
		if Ex is not missing value then set Nm to text 1 thru ((offset of Ex in Nm) - 2) of Nm
		set destination to quoted form of (POSIX path of baseFolder & Nm & "/" & fileName)
		do shell script "/usr/bin/ditto " & quoted form of POSIX path of oneItem & " " & destination & " ;/bin/rm -r " & quoted form of POSIX path of oneItem
	end repeat
end open

Although I have very little understanding of half the script, it seems to do exactly what I wanted. Thank you very much! I hope I can write stuff like this at some point. I mean, I had like thirty lines of really basic, basic cut and paste. Really…

I’ll give it a run! Thanks again!

Rick. :cool: