Surjeet Singh
Surjeet Singh

Reputation: 11939

Search For All Directory/Files within Directory and its child Directory in Cocoa

I need to find out all the files and folders whose name has search string as their prefix within the current directory and also within its child directory. Same like finder done searching. I have tried using NSFileManager but it get results only for current directory. Using NSTask I am able to get file/ folder within current directory and also within child directories. but the problem is that i am not able to fetch files and folders in a single search. I can only search for files or folders not for both simultaneously.

Also if i use NStask i am not able to get output by some interval. it return me result when NStask finished. I already tried to use notification NSFileHandleDataAvailableNotification, but it return me data when task completed.

Is there any other way, So that i can search for Directory and files. One other Application Path Finder is already done this. If any one have idea for this. Please help me Thanks

Upvotes: 0

Views: 412

Answers (1)

CRD
CRD

Reputation: 53000

There are many ways to do this. You say you've found a way (no detail) to find the items in the "current directory" - presumably a directory you supply. So an obvious solution is surely to use that, and for each item it returns which is a directory to recursively scan that one as well?

If you want all the items in one go you can use subpathsOfDirectoryAtPath:error:, you can obtain them one at a time using an enumerator returned by enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:, and other ways. Read through the NSFileManager documentation again.

HTH

Upvotes: 1

Related Questions