Create a Multilevel Catalog

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.