Solved

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

Posted on 2000-02-14
6
349 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
Comment Utility
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
Comment Utility
Adjusted points to 100
0
 
LVL 1

Author Comment

by:charlass
Comment Utility
Actually a great answer.
Suppose my question is badly formed:
I need these function in a C++ - programm.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Accepted Solution

by:
voncheesebiscuit earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now