就是先判断硬盘上有无“c:\abc.txt”文件,如果没有则建立该文件,如果已有就不做操作退出。谢谢!

解决方案 »

  1.   

    BOOL CreateFileEx(CString sFile)
    {
    CString sDir;

    sDir = sFile.Left(sFile.ReverseFind('\\') + 1);

    //循环创建目录
    if (!IsFileExist(sDir))
    {
    CString tmp;
    int n = sDir.Find('\\');

    while (tmp != sDir)
    {
    n = sDir.Find('\\', n+1);

    tmp = sDir.Left(n + 1);

    if (!IsFileExist(tmp))
    {
    if (!CreateDirectory(tmp, NULL))
    return FALSE;
    }
    }
    }

    HANDLE h = CreateFile(sFile, 
    GENERIC_READ, 
    FILE_SHARE_READ, 
    NULL, 
    CREATE_NEW, 
    FILE_ATTRIBUTE_NORMAL, 
    NULL);

    if (h == NULL)
    return FALSE;
    else
    {
    CloseHandle(h);

    return TRUE;
    }
    }createfile()
    {
    CString s = "c:\abc.txt"
    if (!PathFileExists(s))
    {
        CreateFileEx(s);
    }
    }
      

  2.   

    mfc?
    Cfile("c:\\abc.txt",CFile::modeCreate  |CFile::modeNoTruncate   )
    这个可以吗?