⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkdir.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
字号:
// mkdir.cpp

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <mbctype.h>
#include "msc.h"
#include "mkdir.h"



//////////////////////////////
//          ANSI斉          //
//////////////////////////////



// 僨傿儗僋僩儕傪嶌傞乮ANSI斉乯
// 恊僨傿儗僋僩儕偑懚嵼偟側偄偲偒偼恊僨傿儗僋僩儕傕嫮惂揑偵嶌傞
// 僨傿儗僋僩儕柤偼僼儖僷僗偱巜掕
// 惉岟偡傟偽 0, 幐攕偡傟偽 0 埲奜傪曉偡
int MakeDirectoryA ( const char *szPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ) {

   char *szFolderNameBuffer = strdup_expand ( szPathName, MAX_PATH, 1 ) ;  // 枛旜偵 0 傪晅壛偡傞偨傔

   int nDepth = 0 ;
   int nStartDepth = 0 ;
   char *szFolderName = szFolderNameBuffer ;
   if ( *( szFolderName + 1 ) == ':' && IsPathSeparator ( *( szFolderName + 2 ) ) ) nStartDepth = 1 ;
   if ( IsPathSeparator ( *szFolderName ) && IsPathSeparator ( *( szFolderName + 1 ) ) ) nStartDepth = 3 ;
   for ( ; *szFolderName ; szFolderName ++ ) {
      if ( IsPathSeparator ( *szFolderName ) ) {
         if ( nDepth >= nStartDepth ) *szFolderName = 0 ;
         nDepth ++ ;
      }
      if ( ismbblead ( (unsigned char) *szFolderName ) && *( szFolderName + 1 ) ) szFolderName ++ ;
   }
   szFolderName ++ ;
   *szFolderName = 0 ;

   szFolderName = szFolderNameBuffer ;
   while ( *szFolderName ) {
      unsigned long dwFileAttributes = GetFileAttributesA ( szFolderNameBuffer ) ;
      if ( dwFileAttributes == (unsigned long) -1 ) {
         if ( ! CreateDirectoryA ( szFolderNameBuffer, lpSecurityAttributes ) ) goto CAUGHT_ERROR ;
      }
      else {
         if ( ! ( dwFileAttributes | FILE_ATTRIBUTE_DIRECTORY ) ) goto CAUGHT_ERROR ;
      }
      szFolderName = strend ( szFolderName ) ;
      *szFolderName = '\\' ;
      szFolderName ++ ;
   }

   free ( szFolderNameBuffer ) ;
   return 0 ;

   CAUGHT_ERROR :
   free ( szFolderNameBuffer ) ;
   return 1 ;
}



//////////////////////////////
//         UNICODE斉        //
//////////////////////////////



// 僨傿儗僋僩儕傪嶌傞乮UNICODE斉乯
// 恊僨傿儗僋僩儕偑懚嵼偟側偄偲偒偼恊僨傿儗僋僩儕傕嫮惂揑偵嶌傞
// 僨傿儗僋僩儕柤偼僼儖僷僗偱巜掕
// 惉岟偡傟偽 0, 幐攕偡傟偽 0 埲奜傪曉偡
int MakeDirectoryW ( const wchar_t *szPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ) {

   wchar_t *szFolderNameBuffer = wcsdup_expand ( szPathName, MAX_LONG_PATH, 1 ) ;   // 枛旜偵 0 傪晅壛偡傞偨傔

   int nDepth = 0 ;
   int nStartDepth = 0 ;
   wchar_t *szFolderName = szFolderNameBuffer ;
   if ( *( szFolderName + 1 ) == ':' && IsPathSeparator ( *( szFolderName + 2 ) ) ) nStartDepth = 1 ;
   if ( IsPathSeparator ( *szFolderName ) && IsPathSeparator ( *( szFolderName + 1 ) ) ) nStartDepth = 3 ;
   for ( ; *szFolderName ; szFolderName ++ ) {
      if ( IsPathSeparator ( *szFolderName ) ) {
         if ( nDepth >= nStartDepth ) *szFolderName = 0 ;
         nDepth ++ ;
      }
   }
   szFolderName ++ ;
   *szFolderName = 0 ;

   szFolderName = szFolderNameBuffer ;
   while ( *szFolderName ) {
      unsigned long dwFileAttributes = GetFileAttributesW ( szFolderNameBuffer ) ;
      if ( dwFileAttributes == (unsigned long) -1 ) {
         if ( ! CreateDirectoryW ( szFolderNameBuffer, lpSecurityAttributes ) ) goto CAUGHT_ERROR ;
      }
      else {
         if ( ! ( dwFileAttributes | FILE_ATTRIBUTE_DIRECTORY ) ) goto CAUGHT_ERROR ;
      }
      szFolderName = wcsend ( szFolderName ) ;
      *szFolderName = '\\' ;
      szFolderName ++ ;
   }

   free ( szFolderNameBuffer ) ;
   return 0 ;

   CAUGHT_ERROR :
   free ( szFolderNameBuffer ) ;
   return 1 ;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -