How do I create a directory in MFC? 
Author Message
 How do I create a directory in MFC?

Hello,

I need to create a directory from MFC.  I know there are several functions
to do this but I would like to know the most appropriate MFC way.  I tried
creating a regular file then setting the directory attribute.  This didn't
work (Could someone please explain why it didn't?) so before I jump off into
mkdir or something else I'd like a little more information.

Thanks,
Ray Mitchell



Tue, 13 Sep 2005 01:58:02 GMT  
 How do I create a directory in MFC?

Quote:

> Hello,

> I need to create a directory from MFC.  I know there are several functions
> to do this but I would like to know the most appropriate MFC way.  I tried
> creating a regular file then setting the directory attribute.  This didn't
> work (Could someone please explain why it didn't?)

Because a directory is not a file.

Quote:
> so before I jump off into
> mkdir or something else I'd like a little more information.

Use the CreateDirectory function from the Win32 API.
I don't think there is an MFC wrapper for that.

-Joe



Tue, 13 Sep 2005 02:38:58 GMT  
 How do I create a directory in MFC?
Here is an handy routine that creates folders all the way down to the last
folder in the path (in case the previous ones weren't there already):

//
// Recursively create a dir path
//
void CreateAllDirectories(CString strDir)
{
 if(strDir.IsEmpty())
  return;

 // remove ending / if exists
 if(strDir.Right(1)=="\\")
  strDir=strDir.Left(strDir.GetLength()-1);

 // base case . . .if directory exists
 if(GetFileAttributes(strDir) != -1)
  return;

 // recursive call, one less directory
 int nFound = strDir.ReverseFind('\\');
  CreateAllDirectories(strDir.Left(nFound));

 // actual work
 CreateDirectory(strDir,NULL);

Quote:
}

HTH,

Tom


Quote:
> Hello,

> I need to create a directory from MFC.  I know there are several functions
> to do this but I would like to know the most appropriate MFC way.  I tried
> creating a regular file then setting the directory attribute.  This didn't
> work (Could someone please explain why it didn't?) so before I jump off
into
> mkdir or something else I'd like a little more information.

> Thanks,
> Ray Mitchell




Wed, 14 Sep 2005 00:28:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Creating a Virtual directory through a program as done by VS.NET IDE

2. MFC or API to Delete Directory and Copy Directory

3. creating a program on cd to create directories and folders on a hard drive

4. Doing lookup with MFC Dao

5. Visual C++ hangs when doing custom build in MFC project

6. Eval of doing large project in VB or MFC

7. can this project be done easily in mfc ?

8. Q: How to create new directory under a new directory under a new directory under...

9. Creating a DLL in MFC to store a class not derived from an MFC class

10. Creating an MFC extention DLL which uses MFC from a static library

11. Can create an IIS virtual directory, in CSharp

12. Creating a Virtual directory through a C# program

 

 
Powered by phpBB® Forum Software