Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 7, 2008, 01:57 AM   #1
hrishidev
macrumors regular
 
Join Date: Dec 2007
finding the the files using cocoa

I have to find 1 file (say "mysetting.xml" ) in every volume of Machine using cocoa ..... i wrote 1 recursive function scanPath to scan the harddisk but its taking long file (may b its going in indefinate loop )

Code:
-(void)scanPath:(NSString *)m_szPath
{
	
	NSFileManager *flManager = [NSFileManager defaultManager];
	BOOL isDir;
	[flManager fileExistsAtPath:m_szPath isDirectory:&isDir];
	
	if(isDir)
		{
			//directory related code here

		NSArray *ContentOfDirectory=[flManager contentsOfDirectoryAtPath:m_szPath error:NULL];
		int contentcount=[ContentOfDirectory count];
		int i;
		for(i=0;i<contentcount;i++)
		{
				NSString *fileName=[ContentOfDirectory objectAtIndex:i];
				NSString *path=[m_szPath stringByAppendingFormat:@"%@%@",@"/",fileName];
				
		
				if([flManager isDeletableFileAtPath:path])
				{	
					NSLog(path);
					[self scanPath:path];
				}
				
			}
			
		}
	else
		{
			//file related code here
			NSString *msg=[NSString stringWithFormat:@"%@%@",@" -File ",[m_szPath lastPathComponent]];
			NSLog(msg);
		}
}

I m calling this function
like this
Code:
[self scanPath:@"/"];
so , how to find the files in cocoa in faster way

Also, when we type anything to find in finder , it returns within seconds .....
so is there any index of all the files which i can use to acess the file
hrishidev is offline   0 Reply With Quote
Old Apr 7, 2008, 02:38 AM   #2
Spike099
macrumors regular
 
Join Date: Feb 2007
Location: Canada
Spotlight

I have never tried integrating with spotlight, but it sounds like spotlight will be a better match for what you want to do.

A quick google search came up with this tutorial.
__________________
MacBook 4GBRam 320GBHDD
iMac 20" 4GBRam 1TBHDD
iPhone 16GB
Cocoa Developer
Spike099 is offline   0 Reply With Quote
Old Apr 7, 2008, 03:15 AM   #3
Krevnik
macrumors 68020
 
Krevnik's Avatar
 
Join Date: Sep 2003
Quote:
Originally Posted by Spike099 View Post
I have never tried integrating with spotlight, but it sounds like spotlight will be a better match for what you want to do.

A quick google search came up with this tutorial.
+1, with some caveats.

Scanning the system directly in the manner shown in the OP is going to be slower than molasses, as you are actually walking the entire hierarchy looking for a file. File systems these days just can't handle that quickly when you are talking about iterating hundreds of thousands of nodes, reading blocks from disk the whole time.

Now, the caveats: Spotlight may not even really solve the problem with this code. It will make it faster, but if there is an underlying flaw in the design, it will let that flaw fester.

A question I have is: what are you attempting to achieve by scanning all drives for particular a file on it? Why can't this file be expected in a known location on the drive, and why must it be on every drive?
__________________
iMac 2013 27", 13" 2012 rMBP, iPad Air, iPhone 6
Krevnik is offline   0 Reply With Quote
Old Apr 7, 2008, 04:56 AM   #4
hrishidev
Thread Starter
macrumors regular
 
Join Date: Dec 2007
"mysetting.xml" is saved in each folder where user has created own set of settings to handle files in that folder by my Application ...

in short the file can be found at all the locations where we can use "New folder" in finder to create folder.

BTW ,started study of spotlight query programming .....

Last edited by hrishidev; Apr 7, 2008 at 04:59 AM. Reason: added some more text
hrishidev is offline   0 Reply With Quote
Old Apr 7, 2008, 06:28 AM   #5
gnasher729
In Time-Out
 
Join Date: Nov 2005
Quote:
Originally Posted by hrishidev View Post
"mysetting.xml" is saved in each folder where user has created own set of settings to handle files in that folder by my Application ...
This sounds very worrying. You haven't said anything about what you try to achieve here, but I wouldn't want to use an application that puts xml files in lots of directories unless you give me a very, very good reason.
gnasher729 is offline   0 Reply With Quote
Old Apr 7, 2008, 12:48 PM   #6
Krevnik
macrumors 68020
 
Krevnik's Avatar
 
Join Date: Sep 2003
Quote:
Originally Posted by gnasher729 View Post
This sounds very worrying. You haven't said anything about what you try to achieve here, but I wouldn't want to use an application that puts xml files in lots of directories unless you give me a very, very good reason.
+1. There is a huge uproar over the .DS_Store files for a reason. Please don't introduce an app that compounds the issue by making it worse.

Unless you are spewing information like this across thousands of directories, you are better off simply storing the information for various paths in a single file. Hell, even if you get to the thousands of directories part, you can probably keep it fast using SQLite and CoreData.
__________________
iMac 2013 27", 13" 2012 rMBP, iPad Air, iPhone 6
Krevnik is offline   0 Reply With Quote
Old Apr 7, 2008, 11:32 PM   #7
hrishidev
Thread Starter
macrumors regular
 
Join Date: Dec 2007
My app doesnt create files everywhere like .DS_Store , but at very few places where user decides to keep the files of my app ...

BTW , spotlight query programming met my requirements .....
Thank you all
hrishidev is offline   0 Reply With Quote
Old Apr 8, 2008, 12:30 AM   #8
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
If those locations are on a volume that has Spotlight disabled, then I don't think the code will work, but I could be wrong.
kainjow is offline   0 Reply With Quote
Old Apr 8, 2008, 01:17 AM   #9
Krevnik
macrumors 68020
 
Krevnik's Avatar
 
Join Date: Sep 2003
Quote:
Originally Posted by kainjow View Post
If those locations are on a volume that has Spotlight disabled, then I don't think the code will work, but I could be wrong.
You are right, it won't.

This is another reason to try to centralize settings or information about these locations and store it somewhere you can get to easily... rather than hunting for them.

Can you give us a vague idea why there are these folders managed by your application? Are we talking things like multiple iTunes libraries where you have these repositories with a DB describing it?
__________________
iMac 2013 27", 13" 2012 rMBP, iPad Air, iPhone 6
Krevnik is offline   0 Reply With Quote
Old Apr 8, 2008, 01:35 AM   #10
Sbrocket
macrumors 65816
 
Sbrocket's Avatar
 
Join Date: Jun 2007
Location: /dev/null
Quote:
but at very few places where user decides to keep the files of my app
I think the hunting for files on startup or whatever represents a lack of design forethought. Why not just keep a data store rather than writing .xml files all over the user's harddrive? Not to mention, what happens if they delete one by accident or by not knowing what it is? Are these "files of your app" actually created by the app itself, and if so why not just keep a persistent store of where these files are with linked data that you would have stuck in the .xml file instead?
Sbrocket 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
New rMBP - finder not finding most files when searching? cmm OS X Mavericks (10.9) 4 Mar 26, 2014 01:21 PM
finding m4a music files using finder chuck taylor OS X 2 Jan 2, 2014 02:36 PM
Best App for Finding Duplicate files? techguy40 Mac Applications and Mac App Store 13 Dec 6, 2013 05:59 PM
Finding files in Time Machine? DisplacedMic OS X Mavericks (10.9) 2 Nov 9, 2013 02:02 PM

Forum Jump

All times are GMT -5. The time now is 03:19 PM.

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

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