Thread: Scanning ...

  1. #1
    Registered User
    Join Date
    Nov 2005

    Cool Scanning ...

    I have tried a lot of methods but all have failed so I need some help from wounderful smart people like you

    I am trying to scan a single directory and return all the files in that directory.

    Does anyone know how I can go about this?


  2. #2
    Registered User
    Join Date
    Aug 2005
    depends on the operating system but all of them involve some sort of recursion. For MS-Windows see FindFirstFile() and FindNextFile() win32 api functions. When a directory is encountered, make a recursive call and start all over again in the new directory.

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    You could just use the system function (which sends commands to the OS).
    But instead of call it, cout it.

    For a Windows based OS, the following will work:
    #include <iostream>
    using namespace std;
    int main ()
    	cout << system("dir");
    return 0;
    Just search google for attributes to dir command, say for alphabetical order, by file size, ect. If that is what you are asking/trying to do?

    The code I posted will just display the directory of the exe. See google dir search for displaying it for any directory. Just remember to ‘escape’ the \ in c++ so it would be c:\\directory.
    Last edited by Enahs; 11-03-2005 at 04:46 PM.

  4. #4
    Registered User
    Join Date
    Nov 2005
    What I am trying to do is return each indvidual file in a directory. I cant use FindNextFile etc because to m knowledge they are only for Windows OS, I have a Linux OS. I do like the dir command but I cant see how it would return individual files.


  5. #5
    Registered User
    Join Date
    Jan 2005
    Check the FAQ: Level 3 - Accessing a directory and all the files within it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scanning a list?
    By scarlet00014 in forum C Programming
    Replies: 4
    Last Post: 10-15-2008, 03:25 PM
  2. Scanning cloth.
    By adrianxw in forum Tech Board
    Replies: 3
    Last Post: 04-26-2005, 10:59 AM
  3. scanning in character string
    By zackboll in forum C Programming
    Replies: 12
    Last Post: 11-24-2004, 02:18 AM
  4. scanning in with gets() but not over inputing
    By stephanos in forum C Programming
    Replies: 1
    Last Post: 09-09-2002, 03:38 PM
  5. stopping some scanning
    By aoe in forum C Programming
    Replies: 4
    Last Post: 06-09-2002, 01:50 PM