473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2044
David Jacques <Da***********@ ccrs.nrcan.gc.c a> 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.progr ammer and off-topic here.

--
/-- Joona Palaste (pa*****@cc.hel sinki.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.c a> 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.progr ammer 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.c a> 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[REALLYBIGINTEGE R];
sprintf(command ,"/usr/bin/ls '%s' >.listing",dire ctoryToBeListed );
system(command) ;
FILE *listing = fopen(".listing ","r");
char line[REALLYBIGINTEGE R];
while (fgets(line,lis ting)) {
...
}
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
1998
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 make my life easier I usually put all the templates in one folder and the name of the sub-folder is the name of the template. Instead of updating a file every time would there be a way of listing all the files in one directory, (../template), and all...
15
2523
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 that I had to turn the directory listing into an array and then use "foreach (array as item)" to go through and open each file but I've tried several different approaches and I just can't get it to work. I've been able to make it list the directory...
3
3100
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 put an index.htm on my Tesco home page, I get a:
19
3305
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 = os.listdir(directory)
8
11066
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) index.html site/pagefile/
8
6951
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 thus opens index.htm, I want that file to show a listing of all files in the directory with hyperlinks to them. Thanks for the help, Doug
3
1564
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 thus opens index.htm, I want that file to show a listing of all files in the directory with hyperlinks to them. Thanks for the help, Doug
7
5498
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 enumerate through that array to get my listing. However I am trying to set my application up as a service. And now (after calling methods in a thread using the OnStart() method) it says the directory does not exist (I verified this with a...
5
3485
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 the directory my @valeu =@{$Files}; foreach my $file (parse_dir(\@valeu)) { @Files = $ftp->ls('-lR');
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.