Solved

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

Posted on 2000-02-14
6
365 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Named range not carried over 10 65
zeroMAx challenge 20 111
Detect file exist or not 3 178
I could not set window to top 4 20
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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