msdn says its as simple as Directory:irectoryCreate(path). but it says you have to be #using a dll and thats not working for me. does anyone know how to do this?
msdn says its as simple as Directory:irectoryCreate(path). but it says you have to be #using a dll and thats not working for me. does anyone know how to do this?
That looks like managed C++.
In plain old C/C++, you can use CreateDirectory.
hmm. well i also saw on that site that there was a Directory::Exists() function. i tried just getting rid of the Directory:: but it didn't work. how would i check to see if a directory exists?
Use GetFileAttributes(), and see if the return value is FILE_ATTRIBUTE_DIRECTORY.
so just scan through the files and see if they are a file_attribute_directory and if it is check to see if its the directory i want?
Well I have no idea what you are trying to do here, so I don't know if that idea will work for you.
i just want to see if a directory exists in a certain directory. so could i just scan through all the files in that directory and see if any of those files is the directory that i'm looking for?
GetFileAttributes takes a path so you don't need to scan all the files. Just pass it the path to the directory you wish to check.
hmm. i'm not really getting what everyone is trying to say. i've made a function that works, but i don't know if its the best way. it seems kind of slow.
PHP Code:
int directoryExists(string dpath, string dname)
{
HANDLE hFind;
WIN32_FIND_DATA findData;
dpath += '*';
string fname;
hFind = FindFirstFile(dpath.c_str(), &findData);
while (FindNextFile(hFind, &findData))
{
fname = findData.cFileName;
if (fname == dname)
{
if (findData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
FindClose(hFind);
return (1);
}
}
}
FindClose(hFind);
return (0);
}
Code:int directoryExists(string dpath, string dname) { char completePath[MAX_PATH]; sprintf(completePath,"%s\\%s",dpath,dname); if(GetFileAttributes(completePAth) == FILE_ATTRIBUTE_DIRECTORY) return 1; return 0; }
works like a charm. thank you very much.