Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1056951
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: LINUX

2015-12-02 16:44:56


点击(此处)折叠或打开

  1. #include <sys/stat.h>
  2. #include <sys/types.h>
  3. #include <time.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>

  8. int IsDir(char * pathname);

  9. int main(int argc, char ** argv)
  10. {
  11.     int iRet = -1;

  12.     char path[128];
  13.     
  14.     printf("1*********************************\n");
  15.     
  16.     memset(path, 0, sizeof(path));
  17.     strcpy(path, "/home/eas/src/API_fun/goldlog");
  18.     iRet = IsDir(path);
  19.     printf("iRet = [%d]\n", iRet);
  20.     if(iRet == 0)
  21.     {
  22.         printf("[%s] : 是目录文件!\n", path);
  23.     }
  24.     else
  25.     {
  26.         printf("[%s] : 不是目录文件!\n", path);
  27.         mkdir(path, 0777);
  28.     }
  29.     
  30.     printf("2*********************************\n");
  31.     
  32.     memset(path, 0, sizeof(path));
  33.     strcpy(path, "/home/eas/src/API_fun/goldlog");
  34.     iRet = IsDir(path);
  35.     printf("iRet = [%d]\n", iRet);
  36.     if(iRet == 0)
  37.     {
  38.         printf("[%s] : 是目录文件!\n", path);
  39.     }
  40.     else
  41.     {
  42.         printf("[%s] : 不是目录文件!\n", path);
  43.     }
  44.     
  45.     printf("3*********************************\n");
  46.     
  47.     memset(path, 0, sizeof(path));
  48.     strcpy(path, "/home/eas/src/API_fun/goldlog/20140124");
  49.     iRet = IsDir(path);
  50.     printf("iRet = [%d]\n", iRet);
  51.     if(iRet == 0)
  52.     {
  53.         printf("[%s] : 是目录文件!\n", path);
  54.     }
  55.     else
  56.     {
  57.         printf("[%s] : 不是目录文件!\n", path);
  58.         mkdir(path, 0777);
  59.     }
  60.     
  61.     printf("4*********************************\n");
  62.     
  63.     memset(path, 0, sizeof(path));
  64.     strcpy(path, "/home/eas/src/API_fun/goldlog/20140124");
  65.     iRet = IsDir(path);
  66.     printf("iRet = [%d]\n", iRet);
  67.     if(iRet == 0)
  68.     {
  69.         printf("[%s] : 是目录文件!\n", path);
  70.     }
  71.     else
  72.     {
  73.         printf("[%s] : 不是目录文件!\n", path);
  74.     }
  75.     
  76.     printf("5*********************************\n");
  77.     
  78.     return 0;
  79. }

  80. /***********************************************************
  81.  * 函 数: IsDir()
  82.  * 功能描述: 判断目录文件是否存在
  83.  * 输入参数:pathname    -    长文件名
  84.  * 返 回:0-目录文件存在;1-目录文件不存在
  85.  * 流程描述:
  86.  *    说 明:
  87.  * 修改记录:
  88.  * [修改人] [日期][描述]
  89. ***********************************************************/
  90. int IsDir(char * pathname)
  91. {
  92.     struct stat statbuf;
  93.     memset(&statbuf,0,sizeof(statbuf));
  94.     stat(pathname, &statbuf);
  95.     printf("st_mode = [%o]\n", statbuf.st_mode);
  96.     int iRet = statbuf.st_mode & S_IFDIR;
  97.     printf("iRet = [%o]\n", iRet);
  98.     printf("iRet = [%d]\n", iRet);
  99.     if(iRet > 0)
  100.         return 0;
  101.     else
  102.         return 1;
  103. }

阅读(389) | 评论(0) | 转发(0) |
0

上一篇:memmove函数

下一篇:rename函数

给主人留下些什么吧!~~