Solved

Directory content

Posted on 2001-06-24
8
285 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

749 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