• 13
• 18
• 19
• 27
• 9

Function to read all file names in a directory?

This topic is 4510 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have never had the need to do this before, so I'm not too sure where to start. What is the basic method for a file/folder manipulation program? Essentially, I want to sort all of my media into a database. To do this, I need to get the names of all of the folders and files. This is my plan: I have a folder filled with NES (.nes) roms. I need a simple program that goes to a directory I tell it to, and reads all of the filenames in that folder, placing them into a text file. How do I go about reading all the file names in a folder? (Once i get the names, I can obviously make my own algorithm to parse base on extension). Thanks!

Share on other sites
What programming language? What operating system?

C or C++, WinXP

Share on other sites
I would consider using boost::filesystem.

Share on other sites
You know it's a heck of a lot faster to do this in a shell scripting language, including MS-DOS batch processing language. dir *.nes > nesfiles.txt to get only the .nes files; vary the wildcards for other formulations.

For straight Win32, see Listing the Files in a Directory.

Otherwise, go with SiCrane's recommendation of boost::filesystem.

Share on other sites
Is it possible for you to use C# (or managed C++)?

It's extremely easy using .NET.

Share on other sites
If you'd rather not include a 200 MB dependency that can't deal with spaces in file-names, here's the native Win32 method.

	WIN32_FIND_DATA	FileData;	HANDLE	hFile = FindFirstFile(Path.c_str(), & FileData);	bool	FileOK = (hFile !=  INVALID_HANDLE_VALUE);	while (FileOK)	{		FileOK = (FindNextFile(hFile, &FileData) != 0);	}

Share on other sites
Thanks for the help! I think I'm on the right track now.

Quote:
 Original post by Daniel MillerIs it possible for you to use C# (or managed C++)?It's extremely easy using .NET.

That is an option. I've done some searching and I think I have some possible links. Thanks!