先要进行文件操作,要获得当前目录,请问各位大哥谁实现过?

解决方案 »

  1.   

    GetCurrentDirectory
    The GetCurrentDirectory function retrieves the current directory for the current process. DWORD GetCurrentDirectory(
      DWORD nBufferLength,  // size, in characters, of directory buffer
      LPTSTR lpBuffer       // pointer to buffer for current directory
    );
     
    Parameters
    nBufferLength 
    Specifies the length, in characters, of the buffer for the current directory string. The buffer length must include room for a terminating null character. 
    lpBuffer 
    Pointer to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory. 
    Return Values
    If the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character. If the function fails, the return value is zero. To get extended error information, call GetLastError. If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character. 
      

  2.   

    CString Path;
        GetModuleFileName(NULL,Path.GetBufferSetLength(MAX_PATH+1),MAX_PATH);//得到文件绝对路径
    DWORD GetCurrentDirectory(
      DWORD nBufferLength,  // size, in characters, of directory buffer
      LPTSTR lpBuffer       // pointer to buffer for current directory
    );当前目录
      

  3.   

    取得当前的目录...
    DWORD GetCurrentDirectory(
      DWORD nBufferLength,  // size, in characters, of directory buffer
      LPTSTR lpBuffer       // pointer to buffer for current directory
    );char szFileDir[120];
    GetCurrentDirectory(120,szFileDir);
      

  4.   

    http://expert.csdn.net/Expert/topic/1916/1916741.xml?temp=3.825015E-02
    如对话框在OnInitDialog下
    SDI在OnInitialUpdate下
      

  5.   

    CString Path;
    GetModuleFileName(NULL,Path.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
    上面是取得当前可执行文件的绝对路径文件名.
      

  6.   

    CString sPath;
    GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
    sPath.ReleaseBuffer ();
    int nPos;
    nPos=sPath.ReverseFind (_T('\\'));
    sPath=sPath.Left (nPos);
      

  7.   

    楼上
    lpBuffer 
    Pointer to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory. 
    这句话难道不是说这个当前目录是绝对路径吗?
      

  8.   

    要获得程序运行的路径,我给你一个函数:我自己就用的这个函数,呵呵,接分哦。
    CString CXXXXXXApp::GetCurDir()
    {
     TCHAR sDrive[_MAX_DRIVE];
     TCHAR sDir[_MAX_DIR];
     TCHAR sFilename[_MAX_FNAME],Filename[_MAX_FNAME];
     TCHAR sExt[_MAX_EXT];
     GetModuleFileName(AfxGetInstanceHandle(), Filename, _MAX_PATH);
     _tsplitpath(Filename, sDrive, sDir, sFilename, sExt);
     CString homeDir(CString(sDrive) + CString(sDir));
     int nLen = homeDir.GetLength();
     if(homeDir.GetAt(nLen-1) != _T('\\'))
      homeDir += _T('\\');
     return homeDir;
    }
    函数是可行的,稳定的。
      

  9.   

    GetCurrentDirectory方便,地球人都知道啊,就他了
      

  10.   

    GetCurrentDirectory只是当前目录,并非程序所在的目录,
    GetModuleFileNameA才能获得程序所在的目录。
      

  11.   

    G:\开发目录\readfile\Release               //此为GetCurrentDirectory所得路径
    G:\开发目录\readfile\Release\readfile.exe  //GetModuleFileNameA所得路径,但包含本程序文件名然而, 楼主希望:如何获得程序运行的当前目录,并非程序文件名和当前目录
      

  12.   

    GetModuleFileName();
    GetCurrentDirectory();