RE: Quick search through large number of folders
RE: Quick search through large number of folders
- Subject: RE: Quick search through large number of folders
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 18 Aug 2006 10:21:18 -0700
>>Bret>>I have a network volume with over 16,000 folders in it - same level (part of our Pre-Press archive system). Using Sherlock to search for specific folder names (eg. D44321) was taking too long (probably because it was looking into the entire contents of every folder too) so I thought I could write a quick AppleScript that would look at the top level only.
I'm on digest, so others will probably have chimed in before me, but:
Here's a version of your script that does basically the same thing, only much faster. It gets a list of folder names from the finder, creates a string with those names, and locates the name you were looking for. It uses text item delimiters, which is much faster than stepping through one item at a time. I've used a similar routine for other purposes and it's very reliable. (See the first example below)
But, if all you're doing is verifying that a folder with that particular name exists, there's even a faster way.
If you create a string, using the path for the folder you're searching and the name of the folder you're searching for, and try to coerce that string to an alias, then if the folder is there it works and you have a valid alias to the folder which you can use in your script. If the folder doesn't exist, the script will error, which you can trap, and go on with your script.
See the second example below.
--First example
on run
tell application "Finder"
set myFolder to choose folder with prompt "Choose folder to search."
set itemlist to name of every folder of myFolder as list
set DNum to text returned of (display dialog "Please enter a D*Number (eg. D12345):" buttons {"OK"} default button 1 default answer "")
end tell
set myCount to count of itemlist
set itemlist to {""} & itemlist & {""}
set AppleScript's text item delimiters to return
set textList to itemlist as string
set AppleScript's text item delimiters to {"", DNum, ""} as string
set foundFolder to count of text items of textList
set AppleScript's text item delimiters to ""
if foundFolder > 1 then
set foundFolder to "A folder named " & DNum & " found in " & myFolder as string
end if
tell application "Finder" to display dialog "All finished!" & return & foundFolder buttons {"OK"} default button 1
end run
second example:
on run
set myFolder to choose folder with prompt "Choose folder to search."
set myFolder to myFolder as string
set DNum to text returned of (display dialog "Please enter a D*Number (eg. D12345):" buttons {"OK"} default button 1 default answer "")
set folderToFind to myFolder & DNum & ":"
try
set foundFolder to folderToFind as alias
on error
set foundFolder to ""
end try
display dialog "All finished!" & return & "alias: " & foundFolder as string buttons {"OK"} default button 1
end run
HTH,
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden