472,952 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

listing all files in a directory

I am trying to get a list of all files of a certain extension type on disk
to
do some processing in a loop. The code needs to be portable to UNIX, so
I need to use plain c functionality. Does anyone know of a way to do this ?
Any URLs, code snippets, etc ?
Nov 14 '05 #1
3 1987
David Jacques <Da***********@ccrs.nrcan.gc.ca> scribbled the following:
I am trying to get a list of all files of a certain extension type on disk
to
do some processing in a loop. The code needs to be portable to UNIX, so
I need to use plain c functionality. Does anyone know of a way to do this ?
Any URLs, code snippets, etc ?


You cannot do this in plain C. You cannot (at least not easily) do it as
portable between Windows and UNIX either. UNIX does have its own
specific functions for this, but those would be on-topic on
comp.unix.programmer and off-topic here.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"B-but Angus! You're a dragon!"
- Mickey Mouse
Nov 14 '05 #2
On Mon, 8 Nov 2004 07:35:25 -0500
"David Jacques" <Da***********@ccrs.nrcan.gc.ca> wrote:
I am trying to get a list of all files of a certain extension type on
disk to
do some processing in a loop. The code needs to be portable to UNIX,
so I need to use plain c functionality. Does anyone know of a way to
do this ? Any URLs, code snippets, etc ?


Unfortunately standard C does not include any directory handling, so you
will have to use implementation specific techniques. I would suggest
that comp.unix.programmer would be a good place to start. However, you
should first read the FAQ for that group and read at least a few days
worth of messages to get an idea as to what is acceptable.

If you want something portable to both Windows and Unix then you
have a bigger problem, since MS does things differently so you will need
2 versions of some of the code. However, that would still be off topic for this group.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #3
"David Jacques" <Da***********@ccrs.nrcan.gc.ca> wrote:
# I am trying to get a list of all files of a certain extension type on disk
# to
# do some processing in a loop. The code needs to be portable to UNIX, so
# I need to use plain c functionality. Does anyone know of a way to do this ?
# Any URLs, code snippets, etc ?

If the implementation includes a working system() function and the command
interpretter it calls provides this functionality, then you can start with
something like (for unix)

char command[REALLYBIGINTEGER];
sprintf(command,"/usr/bin/ls '%s' >.listing",directoryToBeListed);
system(command);
FILE *listing = fopen(".listing","r");
char line[REALLYBIGINTEGER];
while (fgets(line,listing)) {
...
}
fclose(listing);
system("/usr/bin/rm .listing");

modulo all the usual caveats about error checks and quote escapes, etc. I think
WIndows allows something similar but with command like 'DIR' or something.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
What kind of convenience store do you run here?
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sims | last post by:
Hi, I have a few different templates that I want to list so my clients can see different styles that are available. So I want to offer them a drop down menu listing all the styles. But to...
15
by: Kim Jensen | last post by:
I'd like to make a directory listing where instead of the entire filename I need it to show the filename minus the extention and get the value of charname= in the file itself. I've been told...
3
by: David Callaghan | last post by:
Hi I've just joined tesco broadband. I've come from NTL. If I don't put an index.htm on my NTL home page it justs lists the files in there when any browser visites my page. If I don't...
19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
8
by: gil | last post by:
Is it possible to prevent a browser from listing the entire contents of a folder? The site, is hosted on my ISP with the following layout- site/ "user name from ISP" pagefile (dir)...
8
by: dougawells | last post by:
Hi - I'm hoping for help with the auto-generation of a hyperlinked listing of all files in a directory. The server I use does not auto-generate this. So, when someone comes to this directory and...
3
by: dougawells | last post by:
Hi - I'm hoping for help with the auto-generation of a hyperlinked listing of all files in a directory. The server I use does not auto-generate this. So, when someone comes to this directory and...
7
by: epikto | last post by:
I have a mapped share that I am trying to get a listing of all the files that it contains. I use the following code to access the contents String files = Directory.GetFiles(path); I can then...
5
by: jain236 | last post by:
HI every body, i am always getting the following error while parsing a directory . i am reading a directory by doing ls and trying to find out the name,type,size, mtime and mode of files from...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.