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 8 3689
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
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
"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
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.
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.
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.
"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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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,...
|
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...
|
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.
...
|
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.
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |