Solved

Directory content

Posted on 2001-06-24
8
282 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Implementing a ResolveEventHandler in C++ 13 115
Load and store *.pnm image file 1 75
Compile GLUT with Visual Studio 2015 1 108
Unresolved External Symbols 3 68
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

910 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

19 Experts available now in Live!

Get 1:1 Help Now