Go Back   MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 13, 2013, 11:56 AM   #1
auslegung
macrumors newbie
 
Join Date: Feb 2013
How do I automatically create and populate folders based on document names

I have hundreds of Word documents that need to be placed into their own folders. These documents are usually named "FirstName LastName-ParentFirstName ParentLastName-etc", or "FirstName LastName-ParentFirstName ParentLastName etc", or mostly "FirstName LastName-etc" and "FirstName LastName etc", the differences being the hyphen or whitespace. I can manually separate them into different folders so that each folder contains the same naming scheme, to make the automation easier.

But how do I create an automator workflow (or something else entirely) to automatically create folders that are named "LastName FirstName-ParentLastName ParentFirstName", then populate the folder with the appropriate document? Is this even possible? If it isn't, are there shortcuts to doing it manually? Thanks!
auslegung is offline   0 Reply With Quote
Old Feb 14, 2013, 01:07 AM   #2
SpetsnaZ99
macrumors member
 
Join Date: Apr 2012
Location: UK
A simple script could do this.
Can you post an example filename for me and ill see what i can do.
i.e. "John Doe-Jane Doe.doc"

Also are you wanting the hyphen stripped out of the folder name?
SpetsnaZ99 is offline   0 Reply With Quote
Old Feb 14, 2013, 09:19 PM   #3
auslegung
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Here are the most common file names:

1. John Smith-Jane Smith-STF.doc
2. John Smith-Jane Smith-STF BHHB.doc
3. Dick Smith-Sue Smith-STF-FGC.doc
4. Beth Smith-STF-FGC.doc
5. Billy Smith-STF.doc
6. Smith STF.doc
7. Bob Smith STF-Florence.doc

I want it to be LastName FirstName-LastName FirstName-STF.doc, for example Smith John-Smith Jane-STF.doc. Anything else I'd like to get rid of, including BHHB, FGC, and Florence, but that's not very important. In fact, changing the name of the document isn't even that important, just the name of the file, which must be LastName FirstName-LastName FirstName. If you need me to identify the most likely naming schemes, they are 1 and 2, above. I can manually move all files that follow 1, for instance, and run the script on those so they'll come out as planned, if that's what you need me to do. I could then edit your script to work with the variants. Thanks!

Quote:
Originally Posted by SpetsnaZ99 View Post
A simple script could do this.
Can you post an example filename for me and ill see what i can do.
i.e. "John Doe-Jane Doe.doc"

Also are you wanting the hyphen stripped out of the folder name?
auslegung is offline   0 Reply With Quote
Old Feb 15, 2013, 09:04 AM   #4
SpetsnaZ99
macrumors member
 
Join Date: Apr 2012
Location: UK
Ive had a go at writing a script but seem to be banging my head on a brick wall. Based on the file name structure of "Dick Smith-Sue Smith-STF-FGC.doc" it works fine, however on the file names "Smith STF.doc" etc it failed (see attached img). Also there are two filenames that clash,"1. John Smith-Jane Smith-STF.doc" and "2. John Smith-Jane Smith-STF BHHB.doc" the 'BHHB' being the difference, this would mean that the two files would be in the same folder. Perhaps someone could offer a suggestion.



Here is the code:-
Code:
tell application "Finder"
	activate
	
	set the selected_items to the selection
	--This checks that items have been selected
	if the selected_items is {} then
		beep
		display dialog "No items selected" buttons {"Cancel"} default button 1
	end if
	--Loop thru all of the selected items
	repeat with this_item in the selected_items
		--Retrieve the filename
		set iName to name of this_item
		
		--Set the string 'theFilename' to the files actual name without the extension
		set theFileName to text 1 thru ((offset of "." in iName) - 1) of iName
		--Seperate the first name from the 'theFilename'
		set fName to text 1 thru ((offset of "-" in theFileName) - 1) of theFileName
		--Seperate the last name from the 'theFilename'
		set LName to text ((offset of "-" in theFileName) + 1) thru -1 of theFileName
		set this_folder to container of this_item
		--An 'IF" statement to check if the 'theFilename' contains the string '-STF'
		--If it does then it will be added to the folder name if not then it will be dismissed
		try
			if iName contains "STF" then
				set theFolder to (make new folder at this_folder with properties {name:word 2 of fName & " " & word 1 of fName & "-" & word 2 of LName & " " & word 1 of LName & "-STF"})
				move this_item to theFolder
			else
				set theFolder to (make new folder at this_folder with properties {name:word 2 of fName & " " & word 1 of fName & "-" & word 2 of LName & " " & word 1 of LName})
				move this_item to theFolder
			end if
		end try
	end repeat
end tell

Last edited by SandboxGeneral; Feb 17, 2013 at 07:47 PM. Reason: Added code tags
SpetsnaZ99 is offline   0 Reply With Quote
Old Feb 17, 2013, 06:14 PM   #5
auslegung
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Thank you! I don't have time right now to implement it, but I should have been more clear in what I said about the file names. There will never be a clash, if there is it's because I provided an unhelpful fake name.

I provided several file names that aren't going to be able to be changed automatically since they don't have the second full name. Those will have to be done manually, but thankfully they are the minority.

What I mostly will need is "John Smith-Jane Smith-STF.doc" to become a folder name "Smith John-Smith Jane" Is that possible to remove the -STF? Perhaps put a line in the script to remove everything after the second hyphen, or just to remove -STF. And if the file is "John Smith-Jane Smith STF.doc" I'll need to remove " STF."

Thanks! What you've already written will work for most of what I need, and I'm sure I can edit it to fit my needs that I outlined above, but if it doesn't take much of anyone's time (assuming the code provided doesn't already fit what I've outlined above), and they feel like it, edit the code as you feel.
auslegung is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Mac Basics and Help

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Document based application, use folders (of any type) as documents printz Mac Programming 0 Oct 30, 2013 01:02 PM
How to Create .TXT Document within Finder curious12 Mac Basics and Help 9 Sep 7, 2013 01:18 PM
How to create list names of folders into Word or PDF ? vim147 Mac Applications and Mac App Store 5 Mar 31, 2013 09:19 AM
A way to automatically create a New Folder based on that date? TheMTtakeover Mac Programming 2 Jan 10, 2013 03:17 PM
Package-based document trouble Starfox Mac Programming 1 Jun 7, 2012 02:59 AM

Forum Jump

All times are GMT -5. The time now is 03:58 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC