• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
飞翔de自我
学习——workstation
博客园    首页    新随笔    联系   管理    订阅  订阅

stat函数

     今天看程序时,看到了stat这个函数,特此备份一下,转载百度百科:

     函数名: stat()

  功 能: 得到文件的信息

  用 法: int _stat(const char *path,struct _stat *buffer)

  程序例:

  // crt_stat.c

  // This program uses the _stat function to

  // report information about the file named crt_stat.c.

  #include <time.h>

  #include <sys/types.h>

  #include <sys/stat.h>

  #include <stdio.h>

  #include <errno.h>

  int main( void )

  {

  struct _stat buf;

  int result;

  char timebuf[26];

  char* filename = "crt_stat.c";

  errno_t err;

  // Get data associated with "crt_stat.c":

  result = _stat( filename, &buf );

  // Check if statistics are valid:

  if( result != 0 )

  {

  perror( "Problem getting information" );

  switch (errno)

  {

  case ENOENT:

  printf("File %s not found.\n", filename);

  break;

  case EINVAL:

  printf("Invalid parameter to _stat.\n");

  break;

  default:

  /* Should never be reached. */

  printf("Unexpected error in _stat.\n");

  }

  }

  else

  {

  // Output some of the statistics:

  printf( "File size : %ld\n", buf.st_size );

  printf( "Drive : %c:\n", buf.st_dev + 'A' );

  err = ctime_s(timebuf, 26, &buf.st_mtime);

  if (err)

  {

  printf("Invalid arguments to ctime_s.");

  exit(1);

  }

  printf( "Time modified : %s", timebuf );

  }

  }

  输出结果:

  File size : 732

  Drive : C:

  Time modified : Thu Feb 07 14:39:36 2002

posted @ 2009-02-25 10:37  小丽yu  阅读(2203)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3