g++: How do I access a list of all files in a folder?

J

Jacob Voytko

I am working with a group to write a program that organizes mp3 files
in a root folder based on tag criteria. The tag readers are written,
we are having trouble finding g++ documentation on reading all files
in a folder, and deciding which files are mp3's. Any help will be
appreciated.
 
V

Victor Bazarov

Jacob said:
I am working with a group to write a program that organizes mp3 files
in a root folder based on tag criteria. The tag readers are written,
we are having trouble finding g++ documentation on reading all files
in a folder, and deciding which files are mp3's. Any help will be
appreciated.


V
 
T

Thomas Ruschival

just use the standard C function readdir()
the best thing about c++ is, you an use almost all th C-Libraries that have been developped ever since K&R invented C

Thomas
 
V

Victor Bazarov

Thomas said:
just use the standard C function readdir()

There no such standard C function. Perhaps you're considering the library
you have for programming your OS as standard. It isn't.
the best thing about c++ is, you an use almost all th C-Libraries that have been developped ever since K&R invented C

That's only true if you use an object-file compatible compiler.

V
 
J

Jacek Dziedzic

Jacob said:
I am working with a group to write a program that organizes mp3 files
in a root folder based on tag criteria. The tag readers are written,
we are having trouble finding g++ documentation on reading all files
in a folder, and deciding which files are mp3's. Any help will be
appreciated.

What's a folder? <g>

- J.
 
J

Jerry Coffin

Thomas Ruschival said:
just use the standard C function readdir()

While readdir is in a standard, it's in the POSIX standard, not the C
standard.
the best thing about c++ is, you an use almost all th C-Libraries that have
been developped ever since K&R invented C

C was invented and in wide use for a LONG time before readdir was
invented (before System V or so, directories also followed the UNIX
dictum that everything be treated as files -- a directory was just a
file full of structures of a specific type).

While Brian Kernighan helped write the original book on C, he did not,
by all accounts, help to invent the language -- if you were going to
give credit to anybody but Dennis Ritchie, possibilities might include
Ken Thompson (invented B, C's progenitor as well as the UNIX system to
which C was so closely bound, early on), Martin Richards (inventor of
BCPL, the progenitor of B) and/or Doug McIlroy (apparently invented
C's preprocessor, among many other things).

Though I wasn't present at the time, so my opinion should be taken
with a grain of salt, my own nomination in this category would
probably be Doug McIlroy -- reading books, papers, etc., it seems to
me like he influenced nearly every part of early UNIX and
(particularly) may have been one of the most careful about getting
things _right_ rather than "close enough."
 
R

Ron Natalie

Jerry said:
C was invented and in wide use for a LONG time before readdir was
invented (before System V or so, directories also followed the UNIX
dictum that everything be treated as files -- a directory was just a
file full of structures of a specific type).

And it still is (actually, the more modern ones have variable length
things in it). Readdir just knows how to parse the directory file.

If I remember correctly, the original directories were just the
following:
struct {
unsigned short ino;
char name[14];
};
repeated.

When a file was removed, it just wrote zero to the ino member.
This led to an activity of artfully creating and deleting files
so that when you did something like:

cat /tmp

after some initial garbage for the files that were actually in use
there would appear a few new lines and some sort of ASCII-art picture.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top