c说话获取当前事变路径的实当代码(windows/linux)
发布时间:2020-12-28 21:53:11 所属栏目:创业 来源:网络整理
导读:Linux 函数名: getcwd 功 能: 取适合前的事变目次 用 法: char *getcwd(char *buf,size_t size); 函数声名: getcwd()会将当前的事变目次绝对路径复制到参数buf所指的内存空间,参数size为buf的空间大
5. 删除目次 int _rmdir( const char *dirname ); // 功 能 : 删除名为dirname的目次. // 头文件 : #include <direct.h> // 返回值 : 乐成返回0 // 失败返回-1,且配置errno为以下三个值之一: // EACCESS : 权限不应承 // ENOTEMPTY : dirname不是文件夹;可能该文件夹不空;或 // 者dirname为当前事变文件夹;可能dirname // 为当根文件夹; // ENOENT : 无该文件或目次 6. 其他操纵 int _access( const char *path,int mode ); // 功 能 : 测定文件/目次存取权限. // 头文件 : #include <io.h> // 参 数 : path - 文件可能目次 // mode - 权限设定,其值如下: // 00 Existence only // 02 Write permission // 04 Read permission // 06 Read and write permission int _chdrive( int drive ); // 功 能 : 变动当前事变驱动器. // 头文件 : #include <direct.h> // 返回值 : 乐成返回0 // 失败返回-1 // 注 释 : 参数声名 // drive =1 : A盘 // drive =2 : B盘 // drive =3 : C盘 ... char* _getdcwd( int drive,char *buffer,int maxlen ); // 功 能 : 得到指定驱动器的当前事变路径. // 头文件 : #include <direct.h> // 返回值 : 乐成返回指向buffer的pointer // 失败返回NULL,且配置errno为以下三个值之一: // ENODEV 无该装备 // ENOMEM 内存不足 // ERANGE 功效超出范畴 // 注 意 : 当第一个参数为 NULL 时,该函数配置errno为ERANGE 测试: // 功 能 : 打印目次path中与模式chRE匹配的全部文件明 // 输 入 : path - 待打印的目次 // chRE - 要求匹配的正则表达式 static void printDir( const char* path,const char* chRE ) { char* chCurPath = getcwd( NULL,0); // 当前事变目次 printf("current work path: %sn",chCurPath ); int ret = _chdir( path ); if ( ret < 0 ) { perror( path ); } char* newPath = getcwd( NULL,0 ); printf("new work path: %sn",newPath); free(newPath); struct _finddata_t data; long hnd = _findfirst( chRE,&data ); // 查找文件名与正则表达式chRE的匹配第一个文件 // 返回独一的搜刮句柄 if ( hnd < 0 ) { perror( chRE ); } int nRet = (hnd <0 ) ? -1 : 1; while ( nRet >= 0 ) { if ( data.attrib == _A_SUBDIR ) // 假如是目次 printf(" [%s]*n",data.name ); else printf(" [%s]n",data.name ); nRet = _findnext( hnd,&data ); } _findclose( hnd ); // 封锁当前句柄 chdir( chCurPath); // 切换回之前的事变目次 free( chCurPath ); } C说话获适合前事变路径和.exe路径 本日在想得到.exe可执行路径的时辰,碰着了坚苦。最后照旧办理了。 char exeFullPath[MAX_PATH]={0}; GetModuleFileName(NULL,exeFullPath,MAX_PATH);//获得措施模块.exe全路径 //接下来把xxx.exe文件名去掉,有以下四种: *strrchr( exeFullPath,'') = 0;//获得C:UsersJovan YangDesktop论文代码UnAPK&Extract all APIDebug strrchr( exeFullPath,'')[0]= 0;//也是获得C:UsersJovan YangDesktop论文代码UnAPK&Extract all APIDebug *(strrchr( exeFullPath,'')+1) = 0;//获得C:UsersJovan YangDesktop论文代码UnAPK&Extract all APIDebug strrchr( exeFullPath,'')[1]= 0;//也是获得C:UsersJovan YangDesktop论文代码UnAPK&Extract all APIDebug 好了,就这样。多找找照旧能办理的。这篇文章到此就竣事了,根基上很具体的先容了windows中常见操纵。 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |