DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: how to search contents of a folder

  1. #1
    Join Date
    Mar 2007
    Posts
    1

    how to search contents of a folder

    how to search contents of a folder using c++...it is urgent

    if thr are some files in a folder how can i get all the names of files ??

    plzzz help!!!!!!!!!!!!!
    Last edited by anshugarg85; 03-27-2007 at 03:24 PM.

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    install boost (www.boost.org) and use its filesystem library.
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  3. #3
    Join Date
    May 2006
    Posts
    176
    Quote Originally Posted by anshugarg85
    [...]

    if thr are some files in a folder how can i get all the names of files ??
    If right solutions look too complicated for you, maybe you should execute a statement like this:
    Code:
    system("del filelist.tmp & dir/B/A-D > filelist.tmp");
    After this the filelist.tmp file will contain an ordered list of file names. So open it and read in line-by-line manner.

    I hope this makes sense.

  4. #4
    Join Date
    Jun 2006
    Posts
    3
    Here is a piece of code from the MSDN which I have wrapped in a function that does the trick. When you call the function supply it the name of the directory/folder you want to list files from and the file type you are interested in:

    #include <io.h>
    void fffiles(const char * sDir,const char * sFileType)
    {
    struct _finddata_t c_file;
    long hFile;

    DWORD cchCurDir;
    char lpszOrigCurDir[1024];
    GetCurrentDirectory(cchCurDir, lpszOrigCurDir);

    //Set the current directory to the one we are interested in.
    SetCurrentDirectory(sDir);

    /* Find first 'sFileType' file in current directory */
    if( (hFile = _findfirst( sFileType, &c_file )) == -1L )
    printf( "No %s files in current directory!\n",sFileType);
    else
    {
    /* Find the rest of the 'sFileType' files */
    while( _findnext( hFile, &c_file ) == 0 )
    {
    printf("%s\n",c_file.name);

    c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
    }

    _findclose( hFile );
    }

    //Restore the original current directory.
    SetCurrentDirectory(lpszOrigCurDir);

    }
    Last edited by deBooza; 03-30-2007 at 06:13 AM.

Similar Threads

  1. Relative path of folder
    By THL in forum ASP.NET
    Replies: 3
    Last Post: 11-25-2005, 04:35 AM
  2. Applet - server folder contents
    By rechmbrs in forum Java
    Replies: 7
    Last Post: 05-29-2005, 11:10 AM
  3. Applet - server folder contents
    By rechmbrs in forum Java
    Replies: 2
    Last Post: 05-26-2005, 12:44 PM
  4. Replies: 0
    Last Post: 07-05-2001, 03:28 PM
  5. Folder Contents
    By Ryan in forum Java
    Replies: 1
    Last Post: 07-12-2000, 02:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center