如c:\aa\bb\cc
当c:\aa不存在时,如何创建bb及cc?用什么函数?我用CreateDirectory("c:\\aa\\bb\\cc",NULL); 创建子目录失败

解决方案 »

  1.   

    我想应是CreateDirectoryEx,但参数很多,如何用啊?
      

  2.   

    试试这个函数
    BOOL CreateDirectoryEx(
      LPCTSTR lpTemplateDirectory,  // pointer to template directory path
      LPCTSTR lpNewDirectory,       // pointer to path of directory to create
      LPSECURITY_ATTRIBUTES lpSecurityAttributes  // pointer to security descriptor
    );
      

  3.   

    这才是你想要的。我也是刚刚知道有这么好一个函数,在项目中已经用过了,很爽。
    MakeSureDirectoryPathExists
    The MakeSureDirectoryPathExists function creates all the directories in the specified DirPath, beginning with the root.BOOL MakeSureDirectoryPathExists(
      PCSTR DirPath  
    );
    Parameters
    DirPath 
    [in] Pointer to a null-terminated string that specifies a valid path name. If the final component of the path is a directory, not a file name, the string must end with a backslash (\) character. 
    Return Values
    If the function succeeds, the return value is TRUE.If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError.Res
    Each directory specified is created, if it does not already exist. If only some of the directories are created, the function will return FALSE.All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.Requirements 
      Windows NT/2000/XP: Included in Windows 2000 and later.
      Redistributable: Requires DbgHelp.dll 5.0 or later on Windows NT 4.0 and Windows 95/98/Me.
      Header: Declared in Dbghelp.h.
      Library: Use Dbghelp.lib.See Also
    Debug Help Library Overview, DbgHelp Functions Platform SDK Release: August 2001  What did you think of this topic?
    Let us know.  Order a Platform SDK CD Online
    (U.S/Canada)   (International) 
      

  4.   

    可以先创建aa,再建bb,再建cc啊。
      

  5.   

    刚刚忘了告诉你头文件了。msdn里面写的有错误。在project,setting里面包含上imagehlp.lib
    再包含上头文件imagehlp.h就可以了。
      

  6.   

    Requirements 
      Version 5.00 and later of Shell32.dll  Windows NT/2000: Requires Windows 2000. 
      Header: Declared in shlobj.h. 
      Import Library: shell32.lib.
      

  7.   

    楼上的MakeSureDirectoryPathExists,在VC中使用是有提示,编译不行啊?具体怎么用?
      

  8.   

    刚刚忘了告诉你头文件了。msdn里面写的有错误。在project,setting里面包含上imagehlp.lib
    再包含上头文件imagehlp.h就可以了。
      

  9.   

    void CreateMultiDir( const char* DestChar/*example:"C:/winnttmp/winnttmp/winnt/temp"*/,const char* FindChar/*"/"*/)
    {
       char *pdest;
       int  result;
       char tmpstr[100]="\0";  
       pdest = strstr( DestChar, FindChar );
       result = pdest - DestChar + 1;
       int tmprs=result;
       if (pdest!=NULL)
       {
       pdest = strstr( &DestChar[result], FindChar );
       result=pdest-DestChar + 1;
       }
       while(result>tmprs)
       {
       strncpy(tmpstr,DestChar,result-1);
       CreateDirectory(tmpstr,NULL);
       pdest = strstr( &DestChar[result], FindChar );
       result=pdest-DestChar + 1;
       }
       CreateDirectory(DestChar,NULL);
       
    }
      

  10.   

    IMAGEHLP.dll,这个是WINDOWS自己的,还是VC的,我是否要在安装盘里加上这个文件?
      

  11.   

    IMAGEHLP.dll,这个是WINDOWS自己的,还是VC的,我是否要在安装盘里加上这个文件?
      

  12.   

    GDI32.DLL
    HELLO.EXE
    IMAGEHLP.DLL
    KERNEL32.DLL
    MFC42.DLL
    MSVCRT.DLL
    NTDLL.DLL
    USER32.DLL你可以用dependency walker看一看,上面是需要的,如果你有vc的运行环境,肯定是可以的了,不过保险起见,还是一块编译进去比较好。