Solved

Directory content

Posted on 2001-06-24
8
281 Views
Last Modified: 2011-10-03
I'm looking for a "Directory content" function (like dir in DOS prompt).
0
Comment
Question by:gshriki
8 Comments
 
LVL 10

Accepted Solution

by:
makerp earned 200 total points
ID: 6222538
this is out of my mp3 server, it scans a dirctory for all .MP3 files, hope this helps

void Mp3FileStore::get_tracks(char *path, long album_id)
{
     assert(path != NULL);

     struct _finddata_t ff;
     long fhandle;
     char spath[256], fname[_MAX_FNAME], ext[_MAX_EXT];

     /* make a path with wild card for .mp3 on the end */
     sprintf(spath,"%s\\*.*",path);
     /* open the direcory */
     if((fhandle = _findfirst(spath,&ff)) != -1)
     {
          /* loop through each entry */
          while(!_findnext(fhandle,&ff))
          {    
               /* is it a file */
               if(ff.attrib ^ _A_SYSTEM)
               {
                    /* extract the track name */
                    _splitpath(ff.name,NULL,NULL,fname,ext);          
                    if(!stricmp(ext,".mp3"))
                    {      
                         add_track_to_array(fname,album_id);
                    }
               }
          }
          close(fhandle);
     }

}
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 6222575
If your compiler supports it (virtually all compilers do) take a look at directory streams, in the header <dirent.h>,

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

int
main (void)
{
  DIR *dp;
  struct dirent *ep;

  dp = opendir ("./");
  if (dp != NULL)
    {
      while (ep = readdir (dp))
        puts (ep->d_name);
      (void) closedir (dp);
    }
  else
    puts ("Couldn't open the directory.");

  return 0;
}
0
 

Expert Comment

by:vickirk
ID: 6225635
Take a look at the Boost Library at http://www.boost.org

Within the library is a very easy to use, portable and in the running for inclusion within the next C++ standard library.

It includes iterators to directory contents so you can use the std::library without any wrapping whatso ever.

If you have problems using this just ask.

(Theres lots of other good stuff in the library as well)

Regards,

Vic
0
 
LVL 30

Expert Comment

by:Axter
ID: 6236514
Hi vickirk, welcome to EE.

All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.

An answer should not be posted as an answer, if other experts have previously posted possible answers as comments, and/or have already made contributions to the question.

There are many experts who never post answers as answer.  Instead, they post their answers as comments.

If you read the following link, you'll see why this is the preferred method for many of our valued experts, including myself.

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Hi gshriki:
Feel free to click the [Reject Answer] button near (Answer-poster's) response, even if it seems like a good answer.
Doing so will increase your chance of obtaining additional input from other experts.  Later, you can click the [Select Comment as Answer] button on any response.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:gshriki
ID: 6267902
Sorry vic, couldn't find what I need.
0
 
LVL 10

Expert Comment

by:makerp
ID: 6268219
the solution i proposed will only work on a windows platform, but if thats all you want then cool, KangaRoo's solution will work on linux/unix but i can not find that function on VC++
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 6271056
VC++ is one I don't have :-/ Borlands compilers do implement directory as well as MingW32 Cygwin GCC (apart from just Linux/Unix). So, it depends on which compile/OS, again.
0
 
LVL 10

Expert Comment

by:makerp
ID: 6272231
to be honest i aint used borland for ages, i use DJGPP gcc sometimes
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now