Jump to content
  • Advertisement
Sign in to follow this  
Yourself

Win32 : detecting folders/files

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, Windows, VS.NET 2008 C++ I want to detect all files/folders in a give folder.
Quote:
WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; tstring DirSpec; // directory specification int t=0; DirSpec=_T("D:/C++ Xtra/Labo 5//*"); hFind = FindFirstFile(DirSpec.c_str(), &FindFileData); if(hFind == INVALID_HANDLE_VALUE) { OutputDebugString(_T("ERROR")); OutputDebugString(_T("\n")); } else { OutputDebugString(FindFileData.cFileName); OutputDebugString(_T("\t FIRST FILE \n")); t++; while(FindNextFile(hFind, &FindFileData) != 0) { tstring temp = FindFileData.cFileName; if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) temp.append(_T("\t FOLDER")); else temp.append(_T("\t FILE")); OutputDebugString(temp); OutputDebugString(_T("\n")); t++; } } FindClose(hFind);
it works !! but it always give 2 folder to many :( '.' (==first file found) and '..' (==second found) ... what is this? there are no folders of this kind... somebody has an explanation for this ? grtz

Share this post


Link to post
Share on other sites
Advertisement
Those are the parent directory ".." and the other is something like that as well but I cant remember what it is.

put "dir" into command prompt and youll see what I mean. "cd .." takes you to the parent folder

Share this post


Link to post
Share on other sites
Someone has never used the command line... ;)

'.' is the current folder, '..' the parent folder. They're supposed to be there. Just sort them out when you encounter them in the enumeration.

Share this post


Link to post
Share on other sites
Boost.FileSystem is your friend.


#include "boost/filesystem.hpp"declarations
#include <iostream>
using boost::filesystem;

path my_path( "D:/C++ Xtra/Labo 5/" );

directory_iterator end_itr; // default construction yields past-the-end
for (directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
std::cout << itr->filename() <<
is_directory(itr->status()) ? " Folder" : " File" << std::endl;
}


this won't include "." or ".."

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!