Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 25, 2015, 03:17 AM   #1
SkaFreaks
macrumors newbie
 
Join Date: Jun 2012
Applescript - Number of files in folder to folder name

Hello,
I am trying to get a script that will count the number of files in a selected folder and append it to the end of the folder name. Below is one of the ways I tried which I thought would work but it just keeps giving errors. Any help would be greatly appreciated.

Thanks

Code:
tell application "Finder"
	set FolderPath to selection
	set oldBase to name of FolderPath
	set numFiles to number of files in folder (((FolderPath) as text))
	set newBase to oldBase & numFiles
	
	set FolderPath to newBase
	
end tell
SkaFreaks is offline   0 Reply With Quote
Old Mar 25, 2015, 08:53 AM   #2
superscape
macrumors 6502
 
Join Date: Feb 2008
Location: Yorkshire, UK
Hmmm...

I think you need to have a good read of the Finder scripting dictionary. You're missing a few of the basics. However, I'd approach it something like this:

Code:
tell application "Finder"
	
	set theSelectedFolderList to selection
	
	repeat with theFolder in theSelectedFolderList
		
		if kind of theFolder is "folder" then
			
			set theFileCount to 0
			set theOriginalName to displayed name of theFolder
			set theFileList to every paragraph of (do shell script ("find " & quoted form of POSIX path of (theFolder as alias) & " ! -path \"*/.*\" -type f "))
			
			set name of theFolder to (displayed name of theFolder & " (" & (count of the items of theFileList) & " files)")
		end if
		
		
	end repeat
	
end tell
There are plenty of other methods - many probably better than this!
__________________
Barcode Basics - Barcode creator
Fonty - Find which fonts support a set of characters
Ai Auto Save - Autosave for Illustrator
superscape is offline   0 Reply With Quote
Old Mar 25, 2015, 09:05 AM   #3
SkaFreaks
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
That worked great.
I'm definitely still a beginner when it comes to applescript and everything I've written so far dealt with itunes. I'll do some more reading on the Finder parts of the script.
Thanks for the help.
SkaFreaks is offline   0 Reply With Quote
Old Mar 25, 2015, 09:38 AM   #4
superscape
macrumors 6502
 
Join Date: Feb 2008
Location: Yorkshire, UK
No worries.

A good session looking at the scripting dictionary and poring over a few example scripts will probably be very helpful for you. A bit of trial and error never hurt, and always feel free to ask questions here!

Good luck.
__________________
Barcode Basics - Barcode creator
Fonty - Find which fonts support a set of characters
Ai Auto Save - Autosave for Illustrator
superscape is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 05:58 PM.

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

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