Apple Event: May 7th at 7 am PT

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

Create Folder according to file names

Hello, I've been trying to do something "I thought" would have been very simple to do with Automator but with no success so far.

Work required: I have a single folder (let's call it Root) that contains a lot of files (note there are only files, no subfolders under Root). I want to make a workflow that will create a separate folder within Root based on each file's filename and the respective files will be moved into this folder (note just the filename, no extension.)

Example: Say I have 2 files in Root right now - ABC.zip and XYZ.avi. After I run Root through the workflow, 2 folders will be created within Root, called ABC and XYZ, containing ABC.zip and XYZ in each folder, respectively. There will be no more files within Root but subfolders.



I tried a few times but not sure how I can get the filename of each file and create a folder accordingly. Thanks for the help!!

Macbook Pro 2.8GHz, 4G ram, Mac OS X (10.6.2)

Posted on Feb 1, 2010 6:57 AM

Reply
37 replies

Jun 24, 2012 12:48 AM in response to Duckers

Thanks for posting this script - worked perfectly! Since I am a complete novice with AppleScript (recent convert to the Apple side of the world), I have some reading to do - I would like to save this script for future use. most likely just save as a text file and the next time, just pull it and paste into AppleScript Editor.


cheers - shan

May 4, 2015 3:59 PM in response to V.K.

Hey - I know this is a few years old.... but i just used this script and it was SUPER useful. Had a quick question on a bit of a tweek.


I currently have a folder filled with files that I need to make subfolders with the same name as the files for (exactly what your script does). However - in that folder i have the same file names with 2 different extensions (IE I have one file called Test.WAV & another called Test.M4A)


I'd like to put both those files in a folder called "Test". Is there an easy tweek to your script to do this?

Jan 5, 2016 9:22 PM in response to Classee

That is the exact thing I want to do! I have 888 files, named 1 through 444, .txt and .jpg. I want to put all files with the same number in the same folder with that title. I ran this script, selecting all the files as you said, and I got:


error "Can’t get text 1 thru -2 of \"1\"." number -1728 fromtext 1 thru -2 of "1"

And it highlights:

text 1 thru -((length of cur_ext) + 2)

Unfortunately, I don't know a lot about AppleScript, but this is the exact tool I need. Any help would be greatly appreciated.

Sam

Create Folder according to file names

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