#include<iostream>
#include<string.h>
#include<io.h>
FILE *fp;
using namespace std;
void traval(char name[]);//遍历一个目录
//int i=0;
void main()
{
if((fp=fopen("data.txt","w"))==NULL)
{
cout<<"打开写文件失败!\n";
return;
}
char name[250]="D:\\Code\\Pic\\*.*";
traval(name);
fclose(fp);
}
void traval(char name[])//遍历一个目录
{
char name1[250];
_finddata_t file;
long lf;
if((lf=_findfirst(name,&file))==-1l)
{
cout<<"该目录不存在!\n";
fprintf(fp,"该目录不存在!\n");
}
else
{
while(_findnext(lf,&file)==0)
{
if(file.name[2]==0)continue;
cout<<file.name<<"\t";
fprintf(fp,"%s\t",file.name);
if(file.attrib==0)
{
cout<<"正常 ";
fprintf(fp,"正常 ");
}
if((file.attrib%2)==1)
{
cout<<"只读 ";
fprintf(fp,"只读 ");
}
if((file.attrib==2)||(file.attrib==3)||(file.attrib==6)||(file.attrib==7)||
(file.attrib==18)||(file.attrib==19)||(file.attrib==22)||(file.attrib==23)||
(file.attrib==34)||(file.attrib==35)||(file.attrib==38)||(file.attrib==39)||
(file.attrib==50)||(file.attrib==51)||(file.attrib==54)||(file.attrib==55))
{
fprintf(fp,"%s\t",file.name);
cout<<"隐藏 ";
fprintf(fp,"隐藏 ");
}
if((file.attrib==4)||(file.attrib==5)||(file.attrib==6)||(file.attrib==7)||
(file.attrib==20)||(file.attrib==21)||(file.attrib==22)||(file.attrib==23)||
(file.attrib==36)||(file.attrib==37)||(file.attrib==38)||(file.attrib==39)||
(file.attrib==52)||(file.attrib==53)||(file.attrib==54)||(file.attrib==55))
{
cout<<"系统 ";
fprintf(fp,"系统 ");
}
if((file.attrib>=32&&file.attrib<=55))
{
cout<<"存档 ";
fprintf(fp,"存档 ");
}
if((file.attrib>=16&&file.attrib<=23)||(file.attrib>=48&&file.attrib<=55))
{
cout<<"文件夹 ";
cout<<endl;
fprintf(fp,"文件夹\n");
strcpy(name1,name);
name[strlen(name)-3]='\0';//最后三个字符去掉
name=strcat(name,file.name);//
name=strcat(name,"\\*.*");
cout<<endl<<name<<endl;
//fprintf(fp,"\n%s\n",name1);
traval(name);
strcpy(name,name1);
}
else
{
cout<<endl;
fprintf(fp,"\n");
}
}
}
_findclose(lf);
}

[C]遍历目录下所有文件的更多相关文章

  1. Python遍历目录下所有文件的最后一行进行判断若错误及时邮件报警-案例

    遍历目录下所有文件的最后一行进行判断若错误及时邮件报警-案例: #-*- encoding: utf-8 -*- __author__ = 'liudong' import linecache,sys ...

  2. (实用篇)PHP不用递归遍历目录下所有文件的代码

    <?php /** * PHP 非递归实现查询该目录下所有文件 * @param unknown $dir * @return multitype:|multitype:string */ fu ...

  3. Java精选笔记_IO流【File(文件)类、遍历目录下的文件、删除文件及目录】

    File(文件)类 File类用于封装一个路径,该路径可以是从系统盘符开始的绝对路径,也可以是相对于当前目录而言的相对路径 File类内部封装的路径可以指向一个文件,也可以指向一个目录,在使用File ...

  4. Linux和Windows的遍历目录下所有文件的方法对比

    首先两者读取所有文件的方法都是采用迭代的方式,首先用函数A的返回值判断目录下是否有文件,然后返回值合法则在循环中用函数B直到函数B的返回值不合法为止.最后用函数C释放资源. 1.打开目录 #inclu ...

  5. PHP遍历目录下的文件夹和文件 以及遍历文件下内容

    1.遍历目录下的文件夹和文件: public function bianli1($dir) { $files = array(); if($head = opendir($dir)) { while( ...

  6. Python递归遍历目录下所有文件

    #自定义函数: import ospath="D:\\Temp_del\\a"def gci (path): """this is a stateme ...

  7. shell编程--遍历目录下的文件

    假定目录text下有如下文件      目录:dir_1.dir_2.dir_3 文件:text_1.text_2 遍历目录下所有的文件是目录还是文件 if -- if类型: #!bin/sh for ...

  8. Java遍历目录下全部文件并替换指定字符串

    应用场景:比方有一个深层次的文件目录结构,如:javaAPI 每一个文件中面都有同样的内容,而我们要统一改动为其它内容.上千个文件假设一个个改动显得太不明智. import java.io.Buffe ...

  9. (转)PHP自定义遍历目录下所有文件dir(),readdir()函数

    方法一:使用dir()遍历目录 dir()函数,成功时返回Directory类实例 PHP dir() 语法格式为: dir(directory);//directory为需要显示文件名的目录名称,可 ...

  10. Python遍历目录下xlsx文件

    对指定目录下的指定类型文件进行遍历,可对文件名关键字进行条件筛选 返回值为文件地址的列表 import os # 定义一个函数,函数名字为get_all_excel,需要传入一个目录 def get_ ...

随机推荐

  1. EX:The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

    EX:The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secu ...

  2. 拜拜了,浮动布局-基于display:inline-block的列表布局

    原创文章,转载请注明来自张鑫旭-鑫空间-鑫生活[http://www.zhangxinxu.com]本文地址:http://www.zhangxinxu.com/wordpress/?p=1194

  3. 动态加载(异步加载)jquery/MUI类库 页面加载完成后加载js类库

    动态加载Mui类库: // ==UserScript== // @name // @version 1.4.0 // @author zzdhidden@gmail.com // @namespace ...

  4. MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】

    MVC 默认 Request 方式为Get. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三" ...

  5. linux for循环更改文件名字

    #!/bin/bash # for a in CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo Ce ...

  6. [Linux] - Docker制作nginx+php

    使用Docker制作nginx+php的镜像,这里的镜像是centos + nginx 1.9.7 + php 5.6.14 首先下载到nginx和php: nginx-1.9.5.tar.gz 下载 ...

  7. bzoj3051: [wc2013]平面图

    Description Input Output 扫描线求出平面图的对偶图然后求最小生成树,用并查集按秩合并,以便查询两点间路径最大权 #include<stdio.h> #include ...

  8. 【学】React的学习之旅4-添加事件(onChange)

    实现联动绑定,在文本框中输入内容的同时,后面的span里内容跟着一起变化: onChange(),一旦触发一次变动,就执行某个函数: 既然已经在getInitialState属性里申明了一个变量inp ...

  9. Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(分组背包+dsu)

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invit ...

  10. CentOS下安装Redis及Redis的PHP扩展

    1.安装Redis 1.1 如果没有安装wget,安装wget yum install wget 1.2 在http://redis.io/download页面查看redis版本,并下载安装 wget ...