1#include <iostream>2#include <stdlib.h>3#include <string>4#include <string.h>5 6 using namespacestd;7 8 9 #pragmaWarning (disable:4996)Ten One A #ifdef _WIN32 -#include <direct.h> -#include <io.h> the #elif_linux -#include <stdarg.h> -#include <sys/stat.h> - #endif + - #ifdef _WIN32 + #defineACCESS _access A #defineMKDIR (a) _mkdir ((a)) at #elif_linux - #defineAccess Access - #defineMKDIR (a) MKDIR ((a), 0755) - #endif - - in - intCreatdir (Char*Pdir) to { + inti =0; - intIRet; the intIlen; * Char*Pszdir; $ Panax Notoginseng if(NULL = =Pdir) - { the return 0; + } A the intLen =strlen (pdir); +Pszdir =New Char[len+1]; - strcpy (pszdir,pdir); $ $Ilen =strlen (pszdir); - - //Create an Intermediate directory the for(i =0; i < Ilen; i++ ) - {Wuyi if(Pszdir[i] = ='\\'|| Pszdir[i] = ='/' ) the { -Pszdir[i] =' /'; Wu - //If it does not exist, create AboutIRet = ACCESS (Pszdir,0);//A parameter of 0 indicates the existence of the check file, if the file exists, returns 0, does not exist, returns-1. $ if(IRet! =0 ) - { -IRet = MKDIR (Pszdir);//Create a new directory - if(IRet! =0 ) A { + return-1; the } - } $ //Support Linux, convert all \ swap/ thePszdir[i] ='/'; the } the } the -IRet =MKDIR (pszdir); in returnIRet; the } the About the the voidMain () the { + - Char* PC ="E:/save/game/object/123/abc/1.txt"; the Bayi stringname (PC); the the intIponit = Name.find ("Game" ); - -Name.insert (Iponit,"resbak/"); the the inti = name.find_last_of ("/"); the theName = Name.substr (0, i); - thecout << name <<Endl; the the Const intLen =name.length ();94PC =New Char[Len +1]; the the strcpy (PC, NAME.C_STR ()); the 98cout << pc <<Endl; About - 101 intResult =Creatdir (PC);102 103System"Pause" );104}
Create a Multilevel Catalog