Is there anyway to write a folders contents to file?

H

Hubble

Frank said:
Is there anyway to write a folders contents to file?

Depends on your OS. The simplest way is to use system(3)

system("ls >file");

in a C-Program (provided that there is an ls command on your system)

Most OSs implement opendir/readdir/closedir to parse a directory. Look
into your manuals.

Hubble.
 
W

William Hughes

Frank said:
Is there anyway to write a folders contents to file?

-Frank B.

Yes, use the function

PutTheListOfAllThingsInTheFolderIntoThisString(folder,&string)

Be careful to allocate enough memory for string or the
DS2K will shoot you.

Now write string to a file (as this involves sending
a letter to China, this might take a while).

- William Hughes
 
C

CBFalconer

F

Frank B.

Yes it does. I'm trying to write a program in C which looks into a
directory and copies all the file names in that directory into a file.

Thx
 
K

Keith Thompson

Frank B. said:
Is there anyway to write a folders contents to file?

C has no concept of "folders".

If you post this question to a newsgroup that deals with whatever
platform you're using, be sure to explain just what you mean by
"contents". It could mean a list of file names, the contents of the
files themselves, or something else.
 
S

santosh

Frank said:
Yes it does. I'm trying to write a program in C which looks into a
directory and copies all the file names in that directory into a file.

Thx

As I and others have mentioned standard C has no concept of
directories. You'll have to use an extension. If your platform supports
it, a POSIX function like readdir() would be most portable. Otherwise
you'll have to use whatever your OS or C library offers.

Since this group discusses Standard C, posting to a more specific group
like comp.os.ms-windows or comp.unix.programmer would be preferable.

Finally please don't top-post as this skews the flow of the post's
content and renders it hard to read. See CBFalconer's useful sig. above
for more information.
 
R

Richard Heathfield

Frank B. said:
Yes it does.

Does what?
I'm trying to write a program in C which looks into a
directory and copies all the file names in that directory into a file.

C has no concept of "directory". You are confusing "the C language" with
"features available on my platform". I suggest you ask your question in a
newsgroup devoted to your platform. On some platforms, there is *no*
answer, because some platforms don't have the concept of "directory". (They
have other ways to organise data.) On those platforms that do support the
concept of "directory", the specifics of the answer will vary depending on
the platform and the available libraries.

Try or -
those two seem to be the most likely to meet your needs.
 
K

Keith Thompson

Frank B. said:
Yes it does. I'm trying to write a program in C which looks into a
directory and copies all the file names in that directory into a file.

Please don't top-post. Read these:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

(It took me a while to figure out what "Yes it does." refers to.)

Again, standard C has no concept of directories. There is no portable
solution to your problem. There is almost certainly a non-portable
solution that will work very well on your system. You need to ask in
a newsgroup that deals with whatever platform you're using.
 
M

Mark McIntyre

Yes it does.

Presumably you mean the C language. Please don't top-post in CLC, it
makes posts meaningless. And I'm afraid you're wrong, as C doesn't
have any concept of directories - thats a feature of your OS.
I'm trying to write a program in C which looks into a
directory and copies all the file names in that directory into a file.

The only C way to do that is to use system() and invoke whatever
commadn your OS would use to list the objects in the folder and put
the output into a file.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
J

jmcgill

Frank said:
Is there anyway to write a folders contents to file?

You really want comp.unix.programmer, or a newsgroup on whatever
operating system you happen to be targeting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top