472,958 Members | 2,556 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,958 software developers and data experts.

reading filenames in C

Tim
Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?

I did this, but it seems goofy:

sprintf(t, "ls *.csv > filenames.txt");
system(t);
fptr = fopen("filenames.txt", "r");
while (!(feof(fptr)))
{
fgets(line, 100, fptr);
blah-blah-blah

Is there a way to do this without creating another file?

-Tim
Nov 14 '05 #1
8 3676
Tim wrote:

Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?

I did this, but it seems goofy:

sprintf(t, "ls *.csv > filenames.txt");
system(t);
fptr = fopen("filenames.txt", "r");
while (!(feof(fptr)))
{
fgets(line, 100, fptr);
blah-blah-blah

Is there a way to do this without creating another file?


Not in Standard C, which does not assume a file system
that has a notion of "directory."

<off-topic>"man readdir", and take any further questions
to comp.unix.programmer.</off-topic>

--
Er*********@sun.com
Nov 14 '05 #2
In article <e9**************************@posting.google.com >,
ya*****@hotmail.com says...
Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?
You would be better off asking in one of the Solaris development
groups. This group is about standard C only.
I did this, but it seems goofy:


Yes. I can pretty much guarantee there are better ways to do
it than that on your target platform.

--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 14 '05 #3

"Tim" <ya*****@hotmail.com> wrote:
e9**************************@posting.google.com...
Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?

I did this, but it seems goofy:
...


You can try POSIX functions opendir(), readdir() and closedir():

#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>

int main(void)
{
DIR* pdir = opendir("/");
struct dirent* pent;
if(pdir)
{
while(pent = readdir(pdir))
{
printf("entry: %s\n", pent->d_name);
}
closedir(pdir);
}
return 0;
}

See the manual page for more information.

Best Regards,
Julian
Nov 14 '05 #4
On Wed, 17 Dec 2003 10:23:49 +0800, "Julian Zhang"
<ju******@263.sina.com> wrote in comp.lang.c:

"Tim" <ya*****@hotmail.com> wrote:
e9**************************@posting.google.com...
Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?

I did this, but it seems goofy:
...


You can try POSIX functions opendir(), readdir() and closedir():


Please don't vandalize comp.lang.c with off-topic answers. POSIX is
not topical here. It is in news:comp.unix.programmer and many other
groups.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #5
Tim
As far as C is concerned, how "portable" is POSIX? Would I run into
any trouble if I needed to compile this code in a couple of different
UNIX environments?

<I wasn't sure if this question was better suited to the UNIX
group...>

-Tim

Jack Klein <ja*******@spamcop.net> wrote in message news:<2s********************************@4ax.com>. ..
On Wed, 17 Dec 2003 10:23:49 +0800, "Julian Zhang"
<ju******@263.sina.com> wrote in comp.lang.c:

"Tim" <ya*****@hotmail.com> wrote:
e9**************************@posting.google.com...
Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?

I did this, but it seems goofy:
...


You can try POSIX functions opendir(), readdir() and closedir():


Please don't vandalize comp.lang.c with off-topic answers. POSIX is
not topical here. It is in news:comp.unix.programmer and many other
groups.

Nov 14 '05 #6
Tim
Ignore my question about "portability," after I turned my brain on and
did a quick search over at webopedia.com I realized that POSIX is
designed to make code portable.

Thanks for all the help!
-Tim

Jack Klein <ja*******@spamcop.net> wrote in message news:<2s********************************@4ax.com>. ..
On Wed, 17 Dec 2003 10:23:49 +0800, "Julian Zhang"
<ju******@263.sina.com> wrote in comp.lang.c:

"Tim" <ya*****@hotmail.com> wrote:
e9**************************@posting.google.com...
Does anyone know a way to read the filenames from a given directory in
C in a Solaris environment?

I did this, but it seems goofy:
...


You can try POSIX functions opendir(), readdir() and closedir():


Please don't vandalize comp.lang.c with off-topic answers. POSIX is
not topical here. It is in news:comp.unix.programmer and many other
groups.

Nov 14 '05 #7
Tim writes:
Ignore my question about "portability," after I turned my brain on and
did a quick search over at webopedia.com I realized that POSIX is
designed to make code portable.

Thanks for all the help!
-Tim

Jack Klein <ja*******@spamcop.net> wrote in message

news:<2s********************************@4ax.com>. ..
On Wed, 17 Dec 2003 10:23:49 +0800, "Julian Zhang"
<ju******@263.sina.com> wrote in comp.lang.c:

"Tim" <ya*****@hotmail.com> wrote:
e9**************************@posting.google.com...
> Does anyone know a way to read the filenames from a given directory in > C in a Solaris environment?
>
> I did this, but it seems goofy:
> ...

You can try POSIX functions opendir(), readdir() and closedir():


Please don't vandalize comp.lang.c with off-topic answers. POSIX is
not topical here. It is in news:comp.unix.programmer and many other
groups.


If you look real close at the thread, you will see that Jack Klein, who you
thank, actually chastised someone else for trying to help you. You are a
true gentleman. Or something.
Nov 14 '05 #8
"osmium" <r1********@comcast.net> writes:
[...]
If you look real close at the thread, you will see that Jack Klein, who you
thank, actually chastised someone else for trying to help you. You are a
true gentleman. Or something.


As we've discussed at length here, redirecting off-topic questions to
a more appropriate newsgroup is actually more helpful than trying to
answer them here. If I want to post something about POSIX, I'd much
rather post it over in comp.unix.programmer, where they know enough
about it to correct my inevitable errors.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 14 '05 #9

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

Similar topics

11
by: DaRemedy | last post by:
Hiya, If I had several folders full of images, how can I get PHP to open the folder, read the image names and save the image names (inc extension) to a MySQL database? What I am trying to do...
2
by: rbutch | last post by:
guys, i need a little help with this. this is working (well sort of) i get the info, but it's not moving to a new line as it iterates thru the array and all of the fields are like ONE HUGE LONG...
2
by: Joey Martin | last post by:
Can someone help me with a quick script. I need to browse filenames in a directory and insert them into my sql table. I want to run this in an ASP page. I know how to connect to the database,...
1
by: DOM_scripter | last post by:
Hi, I want to make an automatic foto album that lets me only drop a bunch of pictures in a folder. When I open the browser a javascript should read all the filenames in the folder, show thumbnails...
4
by: Jan Eliasen | last post by:
Hi I am receiving some XML form a component that I can not change. This component reads emails from a POP3 Server and takes the body and attachments and write them in an XML format for me. ...
2
by: aruna sahu | last post by:
Hi, I want to know ,how to read only filenames from a folder in perl? please answer me with an example.
4
waynetheengineer
by: waynetheengineer | last post by:
Hello everyone :) I am trying to write VB code for reading filenames and file property values in a specific directory. For example, I have a directory called C:/Bears and in that directory...
3
by: Joakim Hove | last post by:
Hello, I am reading a filename from the user - the loop is typically like this: 1. Read a directory from the user. 2. Read several filenames from the user. The filenames read in 2. above...
2
by: Manogna | last post by:
hi! all, in a directory nearly 10 zipped file are available. totally the size of the all files is nearly 15GB. i have to retrive the line which dont have the text "ORA" from each file...
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
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...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
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
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...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.