turbo c语言类函数,c语言(turboc)c语言中什么函数能对文件夹进行操作? 爱问知识人...

本文介绍了如何在C语言中使用findfirst和findnext函数遍历目录,包括打开、读取、创建和删除文件及目录的操作。示例代码展示了如何查找和处理文件属性,并提供了fopen函数的使用示例,用于打开文件进行读写操作。同时,还给出了递归遍历目录的思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在C中,使用findfirst和findnext两个函数就可以遍历目录了,例如:structffblkFFileStru;intiValue;iValue=findfirst("c:\\test\\*。*",FFileStru,0);//0表示寻找所有文件和目录while(iValue){。

。。。。。。。。。。//这里是处理语句,有关文件的信息保存在结构变量FFileStru里iValue=findnext(FFileStru);}findfirst的第三个参数可以具有下列值:#defineFA_RDONLY0x01/*Readonlyattribute*/#defineFA_HIDDEN0x02/*Hiddenfile*/#defineFA_SYSTEM0x04/*Systemfile*/#defineFA_LABEL0x08/*Volumelabel*/#defineFA_DIREC0x10/*Directory*/#defineFA_ARCH0x20/*Archive*/遍历一个文件夹可以仿照以上代码写个递归就OK了。

新建文件,就是用FILI读取一个文件,如果文件不存在就#includeFILE*fopen("ugg。txt","w");创建一个ugg。txt文件mkdir("ugg");//创建一个目录rmdir("ugg");//删除一个目录,并且目录不能为空--------------------------------------------------------我写的几个实例,看不懂问我---------------------------------------------------------1。

fopenSyntax:#includeFILE*fopen(constchar*fname,constchar*mode);Thefopen()functionopensafileindicatedbyfnameandreturnsastreamassociatedwiththatfile。

Ifthereisanerror,fopen()returnsNULL。modeisusedtodeterminehowthefilewillbetreated(i。e。forinput,output,etc)ModeMeaning"r"Openatextfileforreading"w"Createatextfileforwriting"a"Appendtoatextfile"rb"Openabinaryfileforreading"wb"Createabinaryfileforwriting"ab"Appendtoabinaryfile"r+"Openatextfileforread/write"w+"Createatextfileforread/write"a+"Openatextfileforread/write"rb+"Openabinaryfileforread/write"wb+"Createabinaryfileforread/write"ab+"Openabinaryfileforread/write *input=fopen("stuff","r");ch=getc(input);-*********************************************************2。

#include#include#includeusingnamespacestd;voidfilesearch(stringpath,intlayer){struct_finddata_tfilefind;stringcurr=path+"\\*。

*";intdone=0,i,handle;if((handle=_findfirst(curr。c_str(),&filefind))==-1)return;while(!(done=_findnext(handle,&filefind))){if(strcmp(filefind。

name,"。。"))//不返回{if((_A_SUBDIR==filefind。attrib)){for(i=0;i>path;filesearch(path,0);system("PAUSE");return0;}。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值