Solved

Directory content

Posted on 2001-06-24
8
287 Views
Last Modified: 2011-10-03
I'm looking for a "Directory content" function (like dir in DOS prompt).
0
Comment
Question by:gshriki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

726 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