How can i check whether a particular directory exists or not?
How can i check if some directory exists or not.
For example if i want to check whether C:\TEMP exists or not. Also if this directory does not exist, how can i create this directory.
Re: How can i check whether a particular directory exists or not?
Hi,
You can try the following,
if(CreateDirectory("C:\\temp123",NULL) == 0)
{
if(ERROR_ALREADY_EXISTS ==GetLastError())
AfxMessageBox("Already existing");
}
If the folder doesn't exist it will create it!!
Regards,
Sreedharan.
Re: How can i check whether a particular directory exists or not?
Re: How can i check whether a particular directory exists or not?
In C#,Its pretty simple.
string destination = @"E:\Songs\sumi songs\fav\";
if (!Directory.Exists(destination))
Directory.CreateDirectory(destination);
C# provides static class "Directory" which is helpfull to do many directory or folder related functionality
Re: How can i check whether a particular directory exists or not?
My understanding is that you need access to the directory for the temporary files. It it's so, simply call the GetTempPath function.
Re: How can i check whether a particular directory exists or not?
Re: MakeSureDirectoryPathExists
One consideration with MakeSureDirectoryPathExists is that it requires one to bring Dbghelp.dll into the address space of one's app, which may be fine if one is using other functions from DbgHelp.dll. One may not wish to load DbgHelp.dll just for the sake of this one function, however.