As if the system provided only the creation of a directory function, but a function to create a multilevel directory was not found, so I wrote one, for reference only.
This code is based on C + + Builder
void __fastcall makedirectory (ansistring Dir)//Create a complex directory
{
Recursively create multilevel catalogs
When a level of directory failure is created, retire a level directory, create a directory, and so on, until the directory is created successfully, and then exit recursively, and the last creation failed directory creation completes
Non-Multilevel directory format
if (Dir.length () <= 3)
{
Return
}
Change path to directory form
if (Dir[dir.length ()] = = =///change path to Directory
{
Dir.delete (Dir.length (), 1);
}
Modify file properties
Win32_find_data WFD;
HANDLE Hfind=findfirstfile (Dir.c_str (), &WFD); Find
if (hfind!= invalid_handle_value)
{
FindClose (hfind);
if (Wfd.dwfileattributes & File_attribute_directory)
Return
}
Failed to create the directory for the current directory
if (Createdir (Dir) = = False)
{
Back level Directory
ansistring newdir = Dir;
while (Newdir[newdir.length ()]!= ' \ \]//To the previous directory in the current directory
{
Newdir.delete (Newdir.length (), 1);
}
Delete symbol \ \
Newdir.delete (Newdir.length (), 1); Will//also delete
Recursive entry
Makedirectory (Newdir); Recursive this function, and then create a table of contents
Directories that failed before they were created recursively exited
Createdir (Dir); Recursive return, building the directory on the existing directory
}
When finished, the directory tree was successfully established.
}
//---------------------------------------------------------------------------