zoukankan      html  css  js  c++  java
  • 获取windows文件夹目录

    获取windows文件夹目录

     1 #include <iostream>
     2 #include <cstring>        // for strcpy(), strcat()
     3 #include <io.h>
     4 
     5 using namespace std;
     6 
     7 void listFiles(const char * dir);
     8 
     9 int main()
    10 {
    11     char dir[200];
    12     cout << "Enter a directory: ";
    13     cin.getline(dir, 200);
    14 
    15     listFiles(dir);
    16 
    17     return 0;
    18 }
    19 
    20 void listFiles(const char * dir)
    21 {
    22     char dirNew[200];
    23     strcpy_s(dirNew, dir);
    24     strcat_s(dirNew, "\*.*");    // 在目录后面加上"\*.*"进行第一次搜索
    25 
    26     intptr_t handle;
    27     _finddata_t findData;
    28 
    29     handle = _findfirst(dirNew, &findData);
    30     if (handle == -1)        // 检查是否成功
    31         return;
    32 
    33     do
    34     {
    35         if (findData.attrib & _A_SUBDIR)
    36         {
    37             if (strcmp(findData.name, ".") == 0 || strcmp(findData.name, "..") == 0)
    38                 continue;
    39 
    40             cout << findData.name << "	<dir>
    ";
    41 
    42             // 在目录后面加上"\"和搜索到的目录名进行下一次搜索
    43             strcpy_s(dirNew, dir);
    44             strcat_s(dirNew, "\");
    45             strcat_s(dirNew, findData.name);
    46 
    47             listFiles(dirNew);
    48         }
    49         else
    50             cout << findData.name << endl;
    51     } while (_findnext(handle, &findData) == 0);
    52 
    53     _findclose(handle);    // 关闭搜索句柄
    54 }
  • 相关阅读:
    uva 10192 Vacation(最长公共子)
    SolrCloud应用简介
    2015第43周一solr相关概念
    2015第42周日
    2015第42周六Pgsql全文索引
    Java注解
    2015第42周四
    2015第42周三
    JS原型函数相关基础知识
    2015第42周一爬虫与反爬虫
  • 原文地址:https://www.cnblogs.com/zmm1996/p/10740852.html
Copyright © 2011-2022 走看看