The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 03:44 PM
unix command to cound the number of files in a folder manas6 UNIX for Dummies Questions & Answers 6 04-21-2008 09:03 AM
ftp a files from a folder dineshr85 Shell Programming and Scripting 2 10-08-2007 02:51 AM
Viewing files of another unix server (in a folder) Djaunl UNIX for Dummies Questions & Answers 3 07-20-2006 11:09 AM
How can i move data files from a server to unix folder shah2 Shell Programming and Scripting 1 03-01-2004 06:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2006
nadiamihu nadiamihu is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 12
unix C++: get the files from a folder

Hello everybody!
How can I get the list of files from a folder in C++ (unix)?

thanks in advance for any help!

regards
  #2 (permalink)  
Old 11-28-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,972
You can do this in plain C, no C++ class madness required.


Code:
// listdir.c
#include <sys/types.h>
#include <dirent.h>

#include <stdio.h>

int main(int argc, char *argv[])
{
  struct dirent *de=NULL;
  DIR *d=NULL;

  if(argc != 2)
  {
    fprintf(stderr,"Usage: %s dirname\n",argv[0]);
    return(1);
  }

  d=opendir(argv[1]);
  if(d == NULL)
  {
    perror("Couldn't open directory");
    return(2);
  }

  // Loop while not NULL
  while(de = readdir(d))
    printf("%s\n",de->d_name);

  closedir(d);
  return(0);
}

For more details, see 'man 3 opendir', 'man 3 readdir', and 'man 3 closedir'.
  #3 (permalink)  
Old 11-29-2006
nadiamihu nadiamihu is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 12
thanks a lot, Corona688!

regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0