Program to retrieve all filenames in drive

K

kevin.watters

Hi all,

I have a need for a short program:

Given a drive letter, it would recursively search through all directories,
"generating" each filename that it encounters (need to pass each filename to
a function).

Can't help but think this "utility" already exists but f**ked if I can find
it.

Any help would be greatly appreciated. Thanks in advance
 
J

jacob navia

kevin.watters said:
Hi all,

I have a need for a short program:

Given a drive letter, it would recursively search through all directories,
"generating" each filename that it encounters (need to pass each filename to
a function).

Can't help but think this "utility" already exists but f**ked if I can find
it.

Any help would be greatly appreciated. Thanks in advance

This has nothing to do with the C language kevin. You are off topic.
But anyway here it is:

DIR C:\ /B /S /AA >tmpfile

tmpfile will contain all files in the drive.
 
K

kevin.watters

Thanks for the prompt reply Jacob, I guess I should be clearer..

This program has to reside on a floppy, and cannot alter the user machine in
any way, so the storing of the tmpfile is a problem (with 68000 files, it is
5M).

I need something that can be used "on the fly", that is, without storing the
filenames. I wrote something in VBScript, called the C function 68000
times, took 6.5 hours, so no good :)

Hope this makes things clearer, and thanks again.

Kevin
 
M

Malcolm

kevin.watters said:
I have a need for a short program:

Given a drive letter, it would recursively search through all directories,
"generating" each filename that it encounters (need to pass each filename
to a function).
Unfortunately you can't do this in ANSI C. There are no "directory"
functions. This is pretty bad and I don't know what the justification is.

However there will certainly be a "readdir" or similar function specific to
the platform you use which accomplishes what you are trying to achieve.
 
K

kevin.watters

Thanks Malcolm,

I figured there would be some extra headers required...

The problem is that we only know the operating system is Windows 98 or
better, but still Microsoft. Not sure what C libraries are standard with
the 98 for example ( the earliest). Haven't looked at C in a while, if I
needed extra libraries, could I put them on the floppy along with the .exe
program, or would they have to reside on the host machine itself? I added a
clarification in the post above, not sure if you noticed it.

Thanks again and any idea where I could find some sample code that does
something similar to what I need, even if not ANSI C (but close enough it
will run on a Microsoft system)

Kevin
 
J

jacob navia

If you need the code of a function that does exactly what you want look at
"Programming with lcc-win32" section 1.33. It describes a program that
calls a function with the name of each file in a drive/directory. All source
is included.

The tutorial of lcc-win32 can be downloaded (at no charge) from
www.cs.virginia.edu/~lcc-win32
Click in the "Tutorial" link
 
K

kevin.watters

Thanks jacob, I will take a look at it, but just to be sure...

I have the function that accepts the filename, I need some program to
generate a list, that I can grab one at a time, of all the files on, for
example, the C drive...

Kevin
 
K

kevin.watters

Terribly sorry, Eric, new to this, thought I could get some help, didn't
necesarily expect courtesy.

I appreciate Jacob's response, I wasn't clear enough in explaining that I
require a C program to provide the "dir" functionality, rather than a DOS
command. Which I tried to explain in another post. How can it be off
topic if I need a C program? And what is a top post?

Thanks.



A: Because it's hard as the very devil to read.
Q: Hates it? Why?
A: You top-posted. We hates it, Precious.
Q: Did I do anything else wrong?
A: You ignored the most important part of Jacob's response,
the part about your question being completely off-topic.
Q: Why is everyone so grumpy? What have I done wrong?
 
E

Eric Sosman

A: Because it's hard as the very devil to read.
Q: Hates it? Why?
A: You top-posted. We hates it, Precious.
Q: Did I do anything else wrong?
A: You ignored the most important part of Jacob's response,
the part about your question being completely off-topic.
Q: Why is everyone so grumpy? What have I done wrong?
 
K

kevin.watters

Hi Keith,

I didn't think a Windows newsgroup would have the required expertise in C
that I find here, but I could be wrong. I didn't think it was a windows
specific issue, it just happens that the systems to be scanned are
guarenteed to be Windows. I guess the point is, that it would be easy with
a Linux system, but harder with windows system?

Kevin
Keith Thompson said:
Try a Windows-specific newsgroup; you'll get better advice than we can
give you here.
 
K

Keith Thompson

kevin.watters said:
Hi all,

I have a need for a short program:

Given a drive letter, it would recursively search through all directories,
"generating" each filename that it encounters (need to pass each filename to
a function).

Can't help but think this "utility" already exists but f**ked if I can find
it.

Try a Windows-specific newsgroup; you'll get better advice than we can
give you here.
 
A

Alan Balmer

This has nothing to do with the C language kevin. You are off topic.
But anyway here it is:

DIR C:\ /B /S /AA >tmpfile

tmpfile will contain all files in the drive.
devtest6 >DIR C:\ /B /S /AA >tmpfile
sh: DIR: not found.

Doesn't seem to work.
 
A

Alan Balmer

Unfortunately you can't do this in ANSI C. There are no "directory"
functions. This is pretty bad and I don't know what the justification is.
Think about it. What if there are no directories?
 
E

Eric Sosman

kevin.watters said:
Terribly sorry, Eric, new to this, thought I could get some help, didn't
necesarily expect courtesy.

I appreciate Jacob's response, I wasn't clear enough in explaining that I
require a C program to provide the "dir" functionality, rather than a DOS
command. Which I tried to explain in another post. How can it be off
topic if I need a C program? And what is a top post?

Top-posting is what you've just done *again*. Here's
another pseudo-verb that might interest you: "to Google"
is to use a Web browser to visit http://www.google.com and
to enter a word or phrase in the nice little box and to
click on the "Search" button. If you Google for the phrase
"top-post" you will learn the answer to your final question.
You will learn it, in fact, from the very first link. Go!

The question "How can it be off topic if I need a C
program" is probably a little too involved for simple
Googling. But consider: C is a general-purpose language,
meaning that it can be used for a wide variety of purposes.
I may want a C program to model the electrical impulses that
flow (oh, so slowly) in the spaces behind my eyes and
between my ears, but that doesn't make neurobiology questions
topical here. I may want a C program to play bridge, but
that doesn't make the Stayman convention topical here. You
may want a C program to catalog all the files in all the
directories on a disk drive, but since the C language and
library knows nothing about (1) directories, (2) disk drives,
or (3) drive letters ... are you beginning to get the drift?
 
K

kevin.watters

Congratulations on your eloquence.

Could you have not just said:

Please do not top-post and here is the answer to your question:

the C language and library knows nothing about (1) directories, (2) disk
drives,
or (3) drive letters , sort of like Malcolm did?

Thanks.
 
C

Chris Torek

... I guess the point is, that it would be easy with
a Linux system, but harder with windows system?

No: the point is that the answer is *different* for Windows and
Linux. Moreover, neither the Windows solution nor the Linux solution
will work on VMS; and the VMS solution will not work on any of
those, nor on AmigaDOS; and so on.

Of course, it is difficult to know a priori whether some technique
will work on "all systems that conform to S" (for whatever system
S you choose) -- but the question "is there an S-specific method
to do this" is on topic in any group, even if the answer is "no".

Here in comp.lang.c the appropriate "specific" is the C Standard,
and the answer to the question "is there a Standard C method to
recursively enumerate all directories" is "no".

Fortunately, there *are* specific methods for all POSIX systems
(including Linux), and (different) specific methods for Windows,
etc. (But for something like IBM's MVS, it gets quite complicated.)
 
K

Keith Thompson

[top-posting unraveled]
kevin.watters said:
I didn't think a Windows newsgroup would have the required expertise in C
that I find here, but I could be wrong. I didn't think it was a windows
specific issue, it just happens that the systems to be scanned are
guarenteed to be Windows. I guess the point is, that it would be easy with
a Linux system, but harder with windows system?

Yes, it is a Windows specific issue. There is no portable C solution
to your problem.

There are several comp.os.ms-windows.programmer.* newsgroups; try
whichever one of them seems most appropriate. (My best guess is
comp.os.ms-windows.programmer.win32, but your guess is probably better
than mine.)

I suppose it's not immediately obvious that a question about Windows
programming in C is topical in comp.os.ms-windows.programmer.win32 but
off-topic in comp.lang.c, but it is.
 
T

Thomas Matthews

kevin.watters said:
Congratulations on your eloquence.

Could you have not just said:

Please do not top-post and here is the answer to your question:

the C language and library knows nothing about (1) directories, (2) disk
drives,
or (3) drive letters , sort of like Malcolm did?

Thanks.

You have proved once again that you can't learn.
Top-posting is when your replies are posted
before or "on top" of the previous post.

Try fixing your newsreader or newsposting program
and try again.

Did you read the FAQ or Welcome.txt yet?
See the links below.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
E

Eric Sosman

Malcolm said:
Then you'd just return an empty list.

What if the directories have multiple entries for the
same file, in the manner of those Windows versions that
support both "long" and "DOS" file names? If you return
all the entries you enumerate many files twice. If you
return only the "DOS" names you deprive the user of the
benefits of the "long" names. If you suppress the "DOS"
names of files that also have "long" names, you exasperate
the users who need to get at the "DOS" names. No one
strategy suits all scenarios, so suddenly you've got to
expand the API somehow.

Or suppose files have version numbers, as in OpenVMS?
VMS itself, of course, has ways to get at all versions of
a file, just the oldest, just the newest, and so on -- but
to get at those capabilities, you've got to expand the API
yet again.

Or suppose files appear several times in a directory
using something like Unix' hard links. To deal with this
intelligently, you again need to expand the API, at least
with some means of determining whether two directory entries
refer to the same inode.

The only language I've personally used that tried to
invent a directory abstraction wide enough to cover all these
cases (and more) was Common LISP -- and believe me, the
edifice was more impressive for its size and complexity than
for its utility. A lot of hard work by very smart people
produced something only a certified genius could use in any
but the simplest settings. Go look it up; it's eye-opening.
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top