linux下取得指定目录所在分区

 获得程序的路径,linux下取得指定目录所在分区的使用信息,也可以取得指定分区名称的使用信息获得程序的路径,linux下取得指定目录所在分区的使用信息,也可以取得指定分区名称的使用信息

 

 

  • //获得程序路径    
  • void GetModulePath(CString &strPath)   
  • {   
  •     TCHAR drive[_MAX_DRIVE];   
  •     TCHAR dir[_MAX_DIR];   
  •     TCHAR fname[_MAX_FNAME];   
  •     TCHAR ext[_MAX_EXT];   
  •     TCHAR szPathName[MAX_PATH];   
  •    
  •     if(GetModuleFileName(NULL, szPathName, MAX_PATH) ==0)   
  •     {   
  •         TRACE(_T("Get module file name error!"));   
  •     }   
  •     _tsplitpath(szPathName, drive, dir, fname, ext );   
  •     strPath = drive;   
  •     strPath += dir;   
  • }   
  •    
  •    
  • //创建目录,实现CreateDirectory函数不能创建子目录的功能    
  • void CreateDir(LPCTSTR lpszPath)   
  • {   
  •     CString strPath(lpszPath);   
  •     if(strPath.GetLength()  3)   
  •         return;   
  •     if(strPath.Right(1) != _T("\\"))   
  •     {   
  •         strPath += _T("\\");   
  •     }   
  •    
  •     int iPos = -1;   
  •     while((iPos = strPath.Find(_T("\\"),iPos + 1)) >= 0)   
  •     {   
  •         CString strDir((LPCTSTR)strPath, iPos);   
  •         CreateDirectory((LPCTSTR)strDir,NULL);   
  •     }   
  • }   
  •    
  • //linux下取得指定目录所在分区的使用信息    
  • //statfs(...)也可以取得指定分区名称的使用信息    
  •    
  • #define B(x,y)  (x)*(y.f_bsize/1024)     
  • //类似于 df -a    
  • int getpathblocks(const char* path)   
  • {   
  •     int nret = 0;   
  •     struct statfs st;   
  •     if(statfs(path,&st) == -1)   
  •     {   
  •         nret = -1;    
  •     }   
  •     else   
  •     {   
  •         printf("%-12s%12s%12s%12s\n","FilePath","1K-blocks","Used","Available");   
  •         printf("%-12s%12ld%12ld%12ld\n",path,B(st.f_blocks,st),B(st.f_blocks,st)-B(st.f_bfree,st),B(st.f_bavail,st));   
  •     }   
  •     return nret;   
  • }   
  • //类似于 df -i    
  • int getpathinodes(const char* path)   
  • {   
  •     int nret = 0;   
  •     struct statfs st;   
  •     if(statfs(path,&st) == -1)   
  •     {   
  •         nret = -1;    
  •     }   
  •     else   
  •     {   
  •         printf("%-12s%12s%12s%12s\n","FilePath","Inodes","IUsed","IFree");   
  •         printf("%-12s%12ld%12ld%12ld\n",path,st.f_files,st.f_files-st.f_ffree,st.f_ffree);   
  •     }   
  •     return nret;   
  • }   

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值