Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SkaFreaks

macrumors newbie
Original poster
Jun 29, 2012
3
0
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
 
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!
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.