获取文件当前目录方法

来源:互联网 发布:gba模拟器mac 编辑:程序博客网 时间:2024/06/08 04:42

方法一

/// 获取当前应用程序的目录inline CString get_app_path( const CString& subFolder = _T("") ){// 获取当前应用程序的句柄HMODULE hApp = ::GetModuleHandleW( NULL );TCHAR buffer[MAX_PATH];memset( buffer, 0 , MAX_PATH );::GetModuleFileNameW( hApp, buffer, MAX_PATH );CString strPath = buffer;{int pos = strPath.ReverseFind( _T('\\') );if( pos < 0 )pos = strPath.ReverseFind( _T('/') );strPath = strPath.Mid( 0, pos+1 );}if ( subFolder.GetLength() > 0 ){strPath += subFolder;strPath += _T("\\");}return strPath;}
方法二
GetCurrentDirectory(MAX_PATH, szCurrentPath);
方法三
<pre name="code" class="cpp">#include <stdlib.h>#include <stdio.h>#include <string>#include <iostream>#include "Python.h"using namespace std;/// 获取当前应用程序的目录//void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext ); 函数来分解开始提到的_pgmptr,然后再用//void _makepath( char *path, const char *drive, const char *dir, const char *fname, const char *ext );int main(int argc, char* argv[]){std::cout << _pgmptr << endl; wchar_t drive[_MAX_DRIVE];wchar_t dir[_MAX_DIR];wchar_t fname[_MAX_FNAME];wchar_t ext[_MAX_EXT];_wsplitpath(_wpgmptr, drive, dir, fname, ext);system("pause");return 0;}


                                             
0 0
原创粉丝点击