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);
        
    
    }


  • 相关阅读:
    在CI框架中的配置整合amfphp
    php操作memcache的使用【转】
    notepad++ 快捷键大全
    utf8_general_ci和utf8_unicode_ci的比较
    50个必备的实用jQuery代码段
    强制浏览器下载PDF文件
    Ajax不能接受php return值的原因
    Proftpd mysql认证配置文档
    CI公用模型
    sublime 相关配置和快捷键
  • 原文地址:https://www.cnblogs.com/huafan/p/11588521.html
Copyright © 2011-2022 走看看