2

How to write a program for executing the 'ls' command in ObjC ? Any API available ?

Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
Biranchi
  • 16,120
  • 23
  • 124
  • 161

3 Answers3

6

NSTask is your friend if speed isn't necessary. If it is, use the native system calls.


If you're only concerned about listing the contents of a directory, read the Guide about Low-Level File Management. Especially Listing the Contents of a Directory could be interesting.$

If that still isn't fast enough, use the C API. See this question: How do you get a directory listing in C.

Community
  • 1
  • 1
Georg Schölly
  • 124,188
  • 49
  • 220
  • 267
3

As far as I'm aware, Objective C is built on C so you should have access to all the standard UNIXy capabilities, among them:

  • system().
  • fork().
  • exec() family.
  • popen().
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

Don't forget about posix_spawn(), for when you need to exert dictatorial-level control over your sub-processes.

Of course, if you're just looking to do file system management and introspection from Cocoa proper, look no further than NSFileManager.

rpj
  • 2,380
  • 2
  • 17
  • 30