Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

Windows API - file system

This topic is 3664 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

Where is the windows API for working with the filesystem? I'm pretty sure there must be some API functions for these but I can't find an documentation at all on the subject... -Getting the contents of a folder -Getting the attributes of a file\folder -Checking if a given file\folder exists -Getting the details of a file (size, last modified, etc) -Creating, copying, moving, deleteing and recycling, files and folders -Lots of other stuff that you can do with an explorer window (access files over ftp for example?) I know alot of this can be done with boost or other libaries but theres got to be some underlying windows API?

Share this post


Link to post
Share on other sites
Advertisement
Thanks.

Ok I'm trying to put together a function to build a directory tree to learn how some of the stuff works. The problem is it's picking up files as well as directories which I think may also be reponsible for a never ending loop when including sub dirs...


HANDLE FirstDir(const std::string &Search, void*FileData)
{
return FindFirstFileEx(
Search.c_str(),
FindExInfoStandard,
FileData,
FindExSearchLimitToDirectories,//shouldn't this stop files being found???
NULL,
NULL);
}
bool NextItem(HANDLE Handle, _WIN32_FIND_DATAA* FileData)
{
return FindNextFile(Handle, FileData) ? true : false;
}
bool DirectoryGetDirectories(std::vector<std::string> *Vector, std::string Directory, bool SubDirs)
{
//if(Directory == "")Directory = fw::DirectoryWorking;
std::set <std::string> ToSearch;

if(Directory == "")ToSearch.insert(Directory);
else ToSearch.insert(Directory + '\\');


WIN32_FIND_DATA FindFileData;
while(!ToSearch.empty())
{
std::string CurrentDirectory = *ToSearch.begin();
HANDLE search = FirstDir(CurrentDirectory + "*", &FindFileData);
do
{
if( FindFileData.cFileName == std::string(".") ||
FindFileData.cFileName == std::string(".."))continue;
std::string Dir = CurrentDirectory + FindFileData.cFileName;
Vector->push_back(Dir);
//only add to search list if checking subdirs
if(SubDirs)ToSearch.insert(Dir + '\\');
}
FindClose(search);
ToSearch.erase(CurrentDirectory);
}
return true;
}






[Edited by - Sync Views on June 6, 2008 4:49:42 AM]

Share this post


Link to post
Share on other sites
Ok ive got that working. Just two things I can't work out:

1- What is the correct way to check if a file/folder exists?
2- How do I rename a file/folder. I really don't think making anew one then deleting the origenal is the correct way...

Share this post


Link to post
Share on other sites
Quote:
Original post by Sync Views
Ok ive got that working. Just two things I can't work out:

1- What is the correct way to check if a file/folder exists?
2- How do I rename a file/folder. I really don't think making anew one then deleting the origenal is the correct way...


1) Take a look at the FindFirstFile function. http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx. If it returns INVALID_HANDLE_VALUE (-1) then most likely the file you are looking for does not exist. You can make sure by calling the GetLastError function. Take a look at their example on that page.

2) Use the MoveFile function: http://msdn.microsoft.com/en-us/library/aa365239.aspx
MoveFile("OldFilename", "NewFilename");

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!