Guest_imported
New member
- Jan 1, 1970
- 0
Am new to C. Is there a wat to create a directory recursively in C???? say C://test1/project/message
Thanx.
Thanx.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <windows.h>
DWORD CreateDir ( char *pb )
// Creates a directory, whose name is stored in pb
// Creates all underlying directories, too.
// return value : 0 if successfull, a win32
// error code if not successfull.
{
if ( CreateDirectory ( pb, NULL )) return 0;
DWORD Erc = GetLastError ( );
if ( Erc == 183 ) return 0; // Already exists --> OK
if ( Erc != 3 ) return Erc; // Path does not exist
char SVDir[MAX_PATH];
strcpy ( SVDir, pb );
BOOL fOK = FALSE;
DWORD i1;
DWORD Depth = 0;
do { for ( i1 = strlen ( SVDir ) - 1;
i1 > 0 && !fOK && SVDir [i1] != '\\';
i1-- );
if ( i1 == 0 ) return Erc;
{ SVDir[i1] = '\0';
if ( CreateDirectory ( SVDir, NULL )) fOK = TRUE; else
{ Erc = GetLastError ( );
if ( Erc == 183 ) fOK = TRUE; else
{ Depth++;
if ( Erc != 3 ) return Erc; } }
} } while ( i1 > 0 && !fOK );
for ( i1 = Depth; i1 > 0; i1-- )
{ SVDir [ strlen ( SVDir )] = '\\';
if ( !CreateDirectory ( SVDir, NULL ))
{ Erc = GetLastError ( );
if ( Erc != 3 ) return Erc; } }
if ( CreateDirectory ( pb, NULL )) return 0;
Erc = GetLastError ( );
return Erc; }
#include <windows.h>
DWORD CreateDir ( char *pb )
// Creates a directory, whose name is stored in pb
// Creates all underlying directories, too.
// return value : 0 if successfull, a win32
// error code if not successfull.
{
BOOL fOK;
DWORD Erc;
DWORD Depth;
DWORD i1;
char SVDir[MAX_PATH];
if ( CreateDirectory ( pb, NULL )) return 0;
Erc = GetLastError ( );
if ( Erc == 183 ) return 0; // Already exists --> OK
if ( Erc != 3 ) return Erc; // Path does not exist
strcpy ( SVDir, pb );
fOK = FALSE;
Depth = 0;
do { for ( i1 = strlen ( SVDir ) - 1;
i1 > 0 && !fOK && SVDir [i1] != '\\';
i1-- );
if ( i1 == 0 ) return Erc;
{ SVDir[i1] = '\0';
if ( CreateDirectory ( SVDir, NULL )) fOK = TRUE; else
{ Erc = GetLastError ( );
if ( Erc == 183 ) fOK = TRUE; else
{ Depth++;
if ( Erc != 3 ) return Erc; } }
} } while ( i1 > 0 && !fOK );
for ( i1 = Depth; i1 > 0; i1-- )
{ SVDir [ strlen ( SVDir )] = '\\';
if ( !CreateDirectory ( SVDir, NULL ))
{ Erc = GetLastError ( );
if ( Erc != 3 ) return Erc; } }
if ( CreateDirectory ( pb, NULL )) return 0;
Erc = GetLastError ( );
return Erc; }
void main ( )
{ CreateDir ( "C:\\A\\B\\C\\D\\E\\F" ); }