473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2015
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.