zoukankan      html  css  js  c++  java
  • 018 时间操作和磁盘读取

    /*
    目录:
       一 时间操作
       二 磁盘读取
    */
    一 时间操作
    void ShowCurrentTime()
    {
        time_t tt;
        time(&tt);
    
        tm *time = localtime(&tt);
        char* ws[] = {
            "星期日",
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六",
        };
    
        printf("%d/%d/%d (%s) %02d:%02d:%02d
    ",
            time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, ws[time->tm_wday],
            time->tm_hour, time->tm_min, time->tm_sec);
    }
    /*
    2019/9/26 (星期四) 00:02:10
    */
    
    int main(int argc, char *argv[], char **envp)
    {
        time_t tt;//long __int64
                  //printf("请输入你的生日:(年月日时分秒)");
        time_t t1 = time(NULL);
        tm time = { 35,11,9,31,11,2015 - 1900 };
        tt = mktime(&time);
        printf("%d", tt);
    
        return 0;
    }
    /*
    1451524295
    */
     二 磁盘读取
    #define  _CRT_SECURE_NO_WARNINGS
    
    #include <stdio.h>
    #include <io.h>
    #include <string.h>
    char sFile[256] = "System.AddIn.dll";
    int IsHiden(unsigned int nAttribute)
    {
        return nAttribute & _A_HIDDEN;
    }
    int IsDirectory(unsigned int nAttribute)
    {
        return nAttribute & _A_SUBDIR;
    
    }
    
    void scanFile(char* path)
    {
        char s[256];
        strcpy(s, path);
        strcat(s, "\*.*");
        struct _finddata_t fd;
        intptr_t hFile = _findfirst(s, &fd);
        if( hFile== -1L)
            return;
        
        do
        {
            if (strcmp(fd.name, ".") && strcmp(fd.name, ".."))
            {
                //printf("%10d %s:
    ", fd.size, fd.name);
                
                if (!strcmp(fd.name, sFile))
                {
                    if (IsDirectory(fd.attrib))
                    {
                        printf("%10s %s:
    ", "文件夹", fd.name);
                    }
                    else
                    {
                        puts(path);
                        printf("%10d %s:
    ", fd.size, fd.name);
                    }
                }
                //如果是目录文件就追加目录进行递归调用:
                if (IsDirectory(fd.attrib))
                {
    
                    char sDir[256];
                    strcpy(sDir, path);
                    strcat(sDir, "\");
                    strcat(sDir, fd.name);
                    scanFile(sDir);
    
                }
            }
            //scanFile(path/xxx);
        }while(_findnext( hFile ,&fd) == 0);
        }
    int main()
    {
        char s[256] = "C:";
        
        //printf("请输入一个磁盘号或者目录名:");
        //scanf_s("%s", s, sizeof(s));
        scanFile(s);
        
    
    }


  • 相关阅读:
    Study Plan The TwentySecond Day
    Study Plan The Nineteenth Day
    Study Plan The TwentySeventh Day
    Study Plan The Twentieth Day
    Study Plan The TwentyFirst Day
    python实现进程的三种方式及其区别
    yum makecache
    JSONPath 表达式的使用
    oracle执行cmd的实现方法
    php daodb插入、更新与删除数据
  • 原文地址:https://www.cnblogs.com/huafan/p/11588521.html
Copyright © 2011-2022 走看看