Solved

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

Posted on 2000-02-14
6
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

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.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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