• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Path to desktop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Path to desktop


  • Subject: Re: Path to desktop
  • From: Chris Parker <email@hidden>
  • Date: Mon, 9 Jul 2007 10:56:24 -0700


On Jul 9, 2007, at 10:37 AM, Shawn Erickson wrote:

On 7/9/07, Micha Fuhrmann <email@hidden> wrote:
Do I really need to reconstruct the full path with
stringByAppendingPathComponent ?

There's got to be something simple!!!

Any help very much appreciated.

Try the following (note -[NSString stringByExpandingTildeInPath] and -[NSString fileSystemRepresentation], the later should be used when passing a path to a POSIX API, etc.)...

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

  NSArray* paths;
  paths = NSSearchPathForDirectoriesInDomains( NSDesktopDirectory,
NSUserDomainMask, NO );
  NSString* fullPathToDesktop = [[paths objectAtIndex:0]
stringByExpandingTildeInPath];
  const char* fullPathToDesktopFS = [fullPathToDesktop
fileSystemRepresentation];
  NSLog(@"NSDesktopDirectory:\n %@ [%s]", fullPathToDesktop,
fullPathToDesktopFS);

  [pool release];
  return 0;
}

Color me (slightly) confused, but...

Why not just pass "YES" to the "expandTilde" parameter for NSSearchPathForDirectoriesInDomains()?

I think you'll find this:

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
NSString * desktop_path = [paths objectAtIndex:0];


gets you all the way there.

.chris

--
Chris Parker
Cocoa Frameworks
Apple, Inc.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Path to desktop
      • From: Micha Fuhrmann <email@hidden>
    • Re: Path to desktop
      • From: "Shawn Erickson" <email@hidden>
References: 
 >Path to desktop (From: Micha Fuhrmann <email@hidden>)
 >Re: Path to desktop (From: "Jim Turner" <email@hidden>)
 >Re: Path to desktop (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: How to keep creation/modification date of a (Core Data) object?
  • Next by Date: NSView drawing optimization question
  • Previous by thread: Re: Path to desktop
  • Next by thread: Re: Path to desktop
  • Index(es):
    • Date
    • Thread