Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 9, 2012, 03:05 PM   #1
nellbern
macrumors newbie
 
Join Date: Mar 2008
File count on different chosen directories

I have been trying for days to make this to work. I need to able to have a pdf file count of the chosen directories in the server.

folder 1 has total of 24 pdfs
folder 2 has 10 pdfs
folder 3 has 234 pdfs

If I select folder 1 & folder 2 I would to see these results

folder 1 24 pdf
folder 2 10 pdf


PHP Code:
set target_folder to choose folder with prompt "Choose target folder to count files" with multiple selections allowed without invisibles

set numberOfFiles to 
do shell script "find " & (quoted form of POSIX path of target_folder) & " -type f  -name *.pdf | wc -l" 

This what I have so far but I'm getting an error:\"Can’t make quoted form of POSIX path of {alias \"Macintosh HD:Users:user:Desktop:Stuff:folder 2 :\", alias \"Macintosh HD:Users:user:Desktop:Stuff:folder1:\"} into type Unicode text." number -1700 from quoted form of POSIX path of {alias "Macintosh HD:Users:user:Desktop:Stuff:folder 2 :", alias "Macintosh HD:Users:user:Desktop:Stuff:folder1:"} to Unicode text

I was trying using only applescript but scripting the finder takes too long to give me results
nellbern is offline   0 Reply With Quote
Old Apr 9, 2012, 04:14 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Since you're allowing multiple selections, the result will be a list (a.k.a. an array). That's what the { } means in the error message: it's showing you that you have a list, and it contains two alias objects.

The solution is just like any other list of things: you apply the action to each item in the array. The AppleScript way to do this is a repeat loop like:
Code:
repeat with thing in listOfThings
  -- code for one thing goes here
end
You should be able to find numerous examples of repeat with loops on the web, or in any AppleScript tutorial that covers looping.

As a test, I suggest writing a repeat loop that simply shows an alert with each item in the array. This will show the loop working. Then you can change it to run the shell script.
chown33 is offline   0 Reply With Quote
Old Apr 10, 2012, 12:14 AM   #3
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Code:
global files_list_count_total
set target_folder to choose folder with prompt "Choose target folders to count files" with multiple selections allowed without invisibles
set files_list_count_total to 0
repeat with i from 1 to the count of target_folder
	set this_item to item i of target_folder
	set the item_info to info for this_item
	if (alias of the item_info is false) and (folder of the item_info is true) then
		process_item(this_item)
	end if
end repeat

-- this sub-routine processes folders 
on process_item(this_item)
	-- NOTE that the variable this_item is a folder reference in alias format 
	-- FOLDER PROCESSING STATEMENTS GOES HERE
	set this_item to this_item as string
	tell application "Finder"
		set files_list to (items of folder this_item whose name extension is "pdf") as alias list
	end tell
	set files_list_count to count files_list
	set files_list_count_total to files_list_count_total + files_list_count
end process_item
display dialog "Total “PDF“ Files: " & files_list_count_total & return & "Folders: " & i with title "Pdf file count" buttons {"OK"} default button 1
If you want to use do shell script use this handler :

Code:
on process_item(this_item)
	-- NOTE that the variable this_item is a folder reference in alias format 
	-- FOLDER PROCESSING STATEMENTS GOES HERE
	set files_list to ((do shell script "find " & quoted form of POSIX path of this_item & " -type f -name *.pdf | wc -l") as integer)
	set files_list_count_total to files_list_count_total + files_list
end process_item
Attached Thumbnails
Click image for larger version

Name:	Afbeelding 1.png
Views:	5
Size:	22.0 KB
ID:	335114  

Last edited by kryten2; Apr 10, 2012 at 08:17 AM. Reason: Added handler with do shell script
kryten2 is offline   0 Reply With Quote
Old Apr 10, 2012, 08:03 AM   #4
nellbern
Thread Starter
macrumors newbie
 
Join Date: Mar 2008
Thank You chown33 for the explanation & kryten2 for the applescript. Have a wonderful day
nellbern 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

Similar Threads
thread Thread Starter Forum Replies Last Post
Will install repair invalid file count? oceanjaws OS X 10.8 Mountain Lion 3 Oct 14, 2013 06:32 AM
Invalid Volume File Count erichowe MacBook Pro 4 Oct 9, 2013 07:12 PM
What color have you chosen? (5C) Vodka iPhone 9 Sep 13, 2013 01:13 PM
Persistently getting "incorrect block count for file" error reddevil0728 OS X 10.8 Mountain Lion 5 Jul 21, 2013 05:36 PM
Backup with different file/folder count -a problem? macstatic OS X 1 Apr 29, 2013 08:04 AM

Forum Jump

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

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

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