Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2000-02-14
6
Medium Priority
?
390 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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