List directory content?

This is a discussion on List directory content? within the C++ Programming forums, part of the General Programming Boards category; hi! this is probably a simple question: how do i list the contents of a directory? i didn't found any ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    244

    List directory content?

    hi!
    this is probably a simple question: how do i list the contents of a directory?
    i didn't found any useful references because they were either overkill-complicated or the headers didn't exist ;(
    thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    For which platform? Alternatively, use the Boost Filesystem library.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    windows

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Check out the FAQ (link in the blue bar above).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    you mean this?
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608

    visual studio 2008 express cant seem to find <dirent.h>
    edit: found the windows example... i guess it could be easier tho?
    got it working now.
    thanks
    Last edited by Devils Child; 03-10-2009 at 06:35 AM.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That is the right FAQ entry, but you probably want the Win32 version, rather than the Linux/Unix/Posix version of the code, which is the third (or so) bit of code posted on that page.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    200 lines of code.
    i dumped them down to this:
    Code:
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <windows.h> 
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	WIN32_FIND_DATA info;
    	HANDLE h = FindFirstFile("*.*", &info);
    	do
    	{
    		if (strcmp(info.cFileName, ".") != 0 && strcmp(info.cFileName, "..") != 0)
    		{
    			cout << info.cFileName << endl;
    		}
    	} while (FindNextFile(h, &info));
    	FindClose(h);
    
    	cin.get();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  2. Replies: 6
    Last Post: 03-02-2005, 01:45 AM
  3. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 08:27 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 05:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21