#include<io.h>
std::string getSelfPath(){
char selfPath[1024];
GetModuleFileName( NULL, selfPath, 1024 );
return selfPath;
}
std::string getSelfExeName(){
std::string s = getSelfPath();
int pos = s.rfind('\\');
std::string newS = s.substr(pos + 1, s.length() - pos - 1);
return newS;
}
std::string getSelfDir(){
std::string s = getSelfPath();
int pos = s.rfind('\\');
std::string newS = s.substr(0, pos);
return newS + "\\";
}
static long getFileLength(std::string file){
FILE *fp =NULL;
long n = 0;
if ((fp = fopen(file.c_str(), "rb")) == NULL)
{
exit(0);
}
fseek(fp,0,2); //指针:移动到文件尾部
n = ftell(fp); //返回指针偏离文件头的位置(即文件中字符个数)
return n;
}
bool exist(const char * lpPath){
/* Check for existence */
if( (_access( "ACCESS.C", 0 )) != -1 )
{
return true;
}else{
return false;
}
}
bool isDir(const char *lpPath){
return GetFileAttributesA(lpPath)&FILE_ATTRIBUTE_DIRECTORY;
}
c++判断文件是否存在,判断是文件还是目录,获取文件大小,获取程序所在路径
最新推荐文章于 2024-07-19 16:14:27 发布