例如:C:\test\test是合法的。c:\\test是不合法的。
还有怎样建立一个多级目录。如:c:\test\t2

解决方案 »

  1.   

    判断合法:PathFileExists
    多级目录:MakeSureDirectoryPathExists
      

  2.   

    我以前也碰到过
    看这个贴子
    http://expert.csdn.net/Expert/topic/2350/2350491.xml?temp=.8053705
      

  3.   

    CString str = "C:\test\test";
    if(file.Create(.....))
       Return TRUE;//合法的
    else
        return FALSE;//不合法
      

  4.   

    用下面这个函数
    BOOL PathFileExists(
        LPCTSTR pszPath
        );
    示例如下:
    #include <windows.h>
    #include <iostream.h>
    #include "Shlwapi.h"void main( void )
    {
    // Valid file path name (file is there).
    char buffer_1[ ] = "C:\\TEST\\file.txt"; 
    char *lpStr1;
    lpStr1 = buffer_1;// Invalid file path name (file is not there).
    char buffer_2[ ] = "C:\\TEST\\file.doc"; 
    char *lpStr2;
    lpStr2 = buffer_2;
    // Return value from "PathFileExists".
    int retval;// Search for the presence of a file with a true result.
    retval = PathFileExists(lpStr1);
    if(retval == 1)
    {
    cout << "Search for the file path of : " << lpStr1 << endl;
    cout << "The file requested \"" << lpStr1 << "\" is a valid file" << endl;
    cout << "The return from function is : " << retval << endl;
    }else{
    cout << "\nThe file requested " << lpStr1 << " is not a valid file" << endl;
    cout << "The return from function is : " << retval << endl;
    }// Search for the presence of a file with a false result.
    retval = PathFileExists(lpStr2);
    if(retval == 1)
    {
    cout << "\nThe file requested " << lpStr2 << "is a valid file" << endl;
    cout << "Search for the file path of : " << lpStr2 << endl;
    cout << "The return from function is : " << retval << endl;
    }else{
    cout << "\nThe file requested \"" << lpStr2 << "\" is not a valid file" << endl;
    cout << "The return from function is : " << retval << endl;
    }
    }
      

  5.   

    1、如果是在写程序的时候,c:\\test是合法的
    参看MSDN中PathFileExists的例子说明:
    ……
    char buffer_1[] = "C:\\TEST\\file.txt"; 
    ……
    retval = PathFileExists(lpStr1);
    if(retval == 1)
    ……2、agree  akiko(弥弥) 
      

  6.   


    CreateDirectory(YourDirectory,NULL)//if func return Nonzero indicates success
    //return Zero indicates failure
      

  7.   

    PathFileExists和MakeSureDirectoryPathExists这两个就行了呀
      

  8.   

    用上面的函数先判断一下是否存在,
    存在则肯定是合法
    不存在可以CreateDirectroy();
    如果失败,则非法
    如果不失败,可以RemoveDirectory();
    合法
      

  9.   

    don't agree to use PathFileExists