Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get list of files in a directory? chdir("..")??

Posted on 2000-02-14
6
Medium Priority
?
395 Views
Last Modified: 2013-12-26
Hello there,
at first: I'm a Mac newbie.
How to get the names of all files in a directory? And why does chdir("..") not work???
I'd prefer answer which uses more the standard c-runtime than Mac-specific features.

Thanx a lot in advance!
chris

0
Comment
Question by:charlass
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:boonstra
ID: 2518643
The Mac doesn't use a command line interface in the Finder, which is why chdir doesn't work.

However, you can download a free development tool called MPW (Macintosh Programmer's Workshop) that does include a command line shell.  Find it at:
<http://developer.apple.com/tools/mpw-tools/>.

The command "Files" will list the files in the current directory (like ls or dir).

The command "Directory" will list the current directory (like pwd).

The command "Directory ::" will list the parent directory.

The command "SetDirectory" is the analog to cd.

You can use the command "Alias" to create aliases and make MPW look like your favorite Un*x environment:
  Alias dir Files
0
 
LVL 1

Author Comment

by:charlass
ID: 2518877
Adjusted points to 100
0
 
LVL 1

Author Comment

by:charlass
ID: 2518878
Actually a great answer.
Suppose my question is badly formed:
I need these function in a C++ - programm.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
voncheesebiscuit earned 300 total points
ID: 2519625
You need to use the File Manager's PBGetCatInfo() function.  First call it to get the information of the directory that you want the listing of.  This will
return the number of files in the directory in the ioDrNmFls field of the
parameter block.  Using that number, iterate over the number of items in
the directory, again using PBGetCatInfo(), to get the information about the
individual files.

The PBGetCatInfo() function is documented at:

<http://developer.apple.com/techpubs/mac/Files/Files-238.html>
0
 
LVL 1

Author Comment

by:charlass
ID: 2521622
Thanx a lot, very detailed answer.
And do you know by chance how to jump to the higher directory (chdir("..") in other OS) ?
0
 

Expert Comment

by:voncheesebiscuit
ID: 2522773
Yep, you need to use the parent directory id (its in the ioDrParID field of
the parameter block) that is returned by PBGetCatInfo(), then use that
id as the current directory id (passed in the ioDrDirID) for further calls to
PBGetCatInfo().
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question