Find Folders --> label index =7 + name of parent folders is "orders"

I am trying to write a script that has to find folders with label index 7 and whose parent folders is “orders”
Is this possible?
The only way - i think - is using the Finder.
Or can do shell script "find " (is faster using -path and maxdepth) also look for Finder labels?

set root to "HD2:Klanten:" as alias
with timeout of 600 seconds
	tell application "Finder"
		set results to (folders of (entire contents of root) whose label index = 7) as text
	end tell
	
	set master_list to {}
	repeat with i from 1 to (count of paragraphs of results)
		if paragraph i of results contains "orders" and paragraph i of results does not end with "orders" then
			copy paragraph i of results to end of master_list
		end if
	end repeat
	
	set new_master_list to {}
	repeat with this_master_item in master_list
		set oldDels to AppleScript's text item delimiters
		set AppleScript's text item delimiters to ":"
		try
			set theText to text item 6 of this_master_item
			if theText is not in new_master_list then copy theText to end of new_master_list
		end try
		set AppleScript's text item delimiters to oldDels
	end repeat
end timeout


choose from list new_master_list

Peter

Hi,

if the volume is indexed by Spotlight you can do it this way


set root to quoted form of POSIX path of "HD2:Klanten:"
set found to paragraphs of (do shell script "/usr/bin/mdfind -onlyin " & root & " 'kMDItemFSLabel  = \"7\" && kMDItemFSName = \"*orders*\" '")
set master_list to {}
set new_master_list to {}
set {TID, text item delimiters} to {text item delimiters, "/"}
repeat with oneParagraph in found
	if oneParagraph does not end with "orders" then
		copy contents of oneParagraph to end of master_list
		copy text item -2 of oneParagraph to end of new_master_list
	end if
end repeat
set text item delimiters to TID

choose from list new_master_list

The fastest way I know to get label index in a search is to use file metadata:

set blueLabel to do shell script "mdfind kMDItemFSLabel == 4" -- blue

This finds all the blue files on my HD. See man mdfind. To identify parameters for this type of search see man mdls, which lists them for a file or folder.

The final path will be on an XServe OS 10.3.9
So using mdfind is not an option for me

Maybe a do shell script find, make HFS path from results and filter out with label index?

–Peter–

Hi Stefan and Adam,

Here’s my solution - 700 folders / 300 with label index 7
Took 15 second to create the the text file.

property TESTARCHIVE : "/klanten"
property textpath : "~/Desktop/joblist_test.txt"
property the_separator : " action= "

set scan_level2 to "4"

set found to paragraphs of (do shell script "/usr/bin/find " & quoted form of TESTARCHIVE & " -path *orders* -type d -maxdepth " & scan_level2)

set master_list to {}
set new_master_list to {}

set {TID, text item delimiters} to {text item delimiters, ":"}
repeat with oneParagraph in found
	if oneParagraph does not end with "orders" then
		copy contents of oneParagraph to end of master_list
	end if
end repeat
repeat with pathRef in master_list
	set pathRef's contents to (POSIX file pathRef) as Unicode text
end repeat

--choose from list master_list

repeat with this_master_item in master_list
	tell application "Finder"
		set job to (this_master_item) as alias
		if label index of job is 7 then
			try
				set theText to text item 6 of this_master_item
			end try
			if theText is not in new_master_list then copy theText to end of new_master_list
		end if
	end tell
end repeat
set text item delimiters to TID

repeat with this_new_master_item in new_master_list
	do shell script "echo " & quoted form of this_new_master_item & the_separator & "Arch" & " >>" & textpath
end repeat

–Peter–