How to create multi-layer directories

xiaoxiao2021-03-06  54

Everyone wants to know that the CreateDirectory () API function in Windows is used to create a directory, but the function is still limited, that is, it can only create a single-layer directory. We often create multi-layer directories when writing applications. Here is a program that creates a multi-layer directory, I hope to help everyone.

Bool CreateMultiPEDirectory (const char * pszdir) {std :: string strdir (pszdir); // Store to create a directory string std :: vector vpath; // stores each layer of directory string STD: : string straTemp; // A temporary variable, store the directory string BOOL BSUCCESS = false; // Success Sign

Std :: string :: const_iterator siter; // Defines the string iterator // Traverse to create the string for (SITER = STRDIR.BEGIN (); SITER! = strdir.end (); SITER ) {if (* siter ! = '//') {// If the current character is not '/' strTemp = (* SITER);} else {// If the current character is '//' vPath.push_back (strTemp); // will currently The string of the layer is added to the array strTemp = '//';}}

// Traverse the array of stored directories, create each layer of directory std :: vector :: const_iterator viter; for (viter = vpath.begin (); viter! = Vpath.end (); viter ) {/ / If CreateDirectory is successful, return true, otherwise return false bsuccess = createDirectory (viter-> c_str (), null)? True: false;}

Return bsuCcess;}

This is a little summary in the work. If you don't have any article, please share it with you, I hope everyone should not laugh! :) If there is any omission, please give you a two!

转载请注明原文地址:https://www.9cbs.com/read-82657.html

New Post(0)