I was wondering if there is a way to import file names from one specific folder to a text file.

for example... my whole music foler.
I want to create a text file for all the songs that I have in that folder. Is it possible and if yes how would I do it! Can anyone guide me in right direction? This is not a school project btw. just doing it for myseld so I can keep track of songs!

Appreciate the help.

To be honest, I'd use a file management program like ZTree. This is something I do quite often and ZTree makes it extremely easy.

don't know why but it doesn't work for me
On top I would love to learn how to do it!

don't know why but it doesn't work for me

What doesn't? Exactly what did you do?

This is a function written in C ( can always be converted to C++ ) to print all files in a given directory.

void searchDir()
{
   char dirname[100] ;


   DIR *dp;
   struct dirent *ep;

   printf("\nEnter directory address that is to be searched (type Exit to exit)\n>>> ");

   fgets(dirname, 100, stdin);

   if(strcmp(dirname,"Exit")==0)
   {
       break;
   }

   dp = opendir (dirname);

   if (dp != NULL)
   {
     while (ep = readdir (dp))
     fputs (ep->d_name, stdout);

     (void) closedir (dp);
   }

   else
     perror ("Couldn't open the directory");


}

Here you can instead of fputs() with stream stdout, revert the output to a specific text file, file stream. Like

FILE *fp ;

fp = fopen ( "text.txt" , "w" );

fputs( ep_dname, fp ) ;

I don't if this will be helpful for you or not.

Thanks np complete for the code! Will check it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.