Thread: Reading File Names

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    1

    Reading File Names

    Hi, how do you read all of the file names that are in a folder? I'll also want to save all the names as a list in a text document, but I already know how to create files I just need to know how to read all of their names.

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    For Windows you would use the FindNextFile() function.

    FindNextFile() MSDN

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Googling around shows that you could do something like this via system():

    For Windows/DOS:

    Code:
    system("dir directory >> files.txt ");
    I believe for *nix systems, the following should work:

    Code:
    system("ls directory >> files.txt ");
    directory would have to be replaced with whatever directory you want to search through. After executing this, the output of the command (including the file list) would be placed inside a file named files.txt.

    Otherwise, I believe you would have to find the O/S specific system calls to get the information you want, such as what Sentral posted.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    630
    Does boost have any portable libary for that kind of purpuse?

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366

  6. #6
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    You can also read our FAQ entry about reading all the files within a directory.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM