导航:首页 > 净水问答 > c过滤文件类型读取文件名

c过滤文件类型读取文件名

发布时间:2020-12-23 22:59:55

⑴ c语言读文件时文件名应如何引用才能打开它

文件名可以直接写进去,也可以放在变量里:
FILE *fp;
char namein[]="abc.txt";
fp=fopen(namein,"r");
或 fp=fopen("abc.txt","r");

文件名若带路径,单反斜杠要写内成双反斜杠,例如容:
char namein[]="C:\\path\\abc.txt";

长路径可用8字母格式缩写:
C:\Documents and Settings\Wang\...缩写:
char namein[]="C:\\Docume~1\\Wang\\abc.txt";

二进制文件打开方式用rb:
fp=fopen("abc.txt","rb"); 或:
fp=fopen(namein,"rb");

⑵ C语言如何判断文件类型

windows下,可以根据文件名的扩展名去判断,如.txt是文本文件,.exe是可执行文件
把文件名存到一个变量s中,用strrchr(s,'.')函数去得到扩展名,进行判断就可以了!

⑶ c语言文件名提取

可以参考 DIR 命令选项 (/os /oe /od /on 等),知道其它排列专方法。
例如:
system("dir *.* /os > m01.txt"); // m01.txt 存放:属按文件大小排列
system("dir *.* /oe > m02.txt"); //m02.txt 存放:按文件扩展名次序排列
system("dir *.* /od > m03.txt"); //m03.txt 存放:按文件日期排列

⑷ c语言中怎么在屏幕上输入文件名然后从此文件中读取内容到屏幕

#include<stdio.h>#include<string.h>voidmain(){intn;doublex,y,z;/*如果需要保存每次数据,可以用数组*/FILE*fp;charfilename[100];charstr[1000];printf("
Enterafilepath/filename:
");gets(filename);fp=fopen(filename,"rt");if(fp==NULL){printf("cannotopenfile
");return;}while(fgets(str,1000,fp))//读取一行,并判断文件是否结束{sscanf(str,"%d,%lf,%lf,%lf
",&n,&x,&y,&z);printf("%d,%e,%e,%e
",n,x,y,z);}fclose(fp);}

⑸ C语言如何读取指定路径下的所有指定格式的文件

用C语言读取目录中的文件名的方法:
1、如果是在window环境下,可以用一下方法:
使用stdlib.h头文件声明的system()函数
_CRTIMP int __cdecl system (const char*);
system("dir c:\ /a:h /b > c:\dir.txt");
调用系统命令dir,把c:目录下文件列表写入文件dir.txt中

2、使用dirent.h头文件中声明的opendir(),readdir()函数;

intmain(intargc,char*argv[])
{
DIR*directory_pointer;
structdirent*entry;

if((directory_pointer=opendir("d:\XL"))==NULL)
printf("Erroropening ");
else
{
while((entry=readdir(directory_pointer))!=NULL)
{
printf("%s ",entry->d_name);
}
closedir(directory_pointer);

}
system("PAUSE");
return0;
}

3、如果没有dirent.h,可以使用io.h头文件中声明的_findfirst(),_findnext()函数;
示例代码:

intmain(intargc,char*argv[])
{
longfile;
struct_finddata_tfind;

_chdir("d:\");
if((file=_findfirst("*.*",&find))==-1L)
{
printf("空白! ");
exit(0);
}
printf("%s ",find.name);
while(_findnext(file,&find)==0)
{
printf("%s ",find.name);
}
_findclose(file);

system("PAUSE");
return0;
}

⑹ 用C语言如何从路径名中分离文件名

void*GetFilename(char*p)
{
intx=strlen(p);
charch='\';
char*q=strrchr(p,ch)+1;

returnq;
}

intmain()
{
charp[]="D:\SoftWare\Adobe\Photoshop5.exe";

printf("%s ",GetFilename(p));
return0;
}

charp[]="D:\SoftWare\Adobe\Photoshop5.exe";

中的双斜杠是赋值时用到的,如果路径名是其它方式获取到回,就不需要答用到双斜杠!

⑺ c语言读取文件名问题

用C语言读取目录中的文件名的方法:

1、如果是在window环境下,可以用一下方法:

使用stdlib.h头文件声明的system()函数

_CRTIMP int __cdecl system (const char*);

system("dir c:\ /a:h /b > c:\dir.txt");

调用系统命令dir,把c:目录下文件列表写入文件dir.txt中

2、使用dirent.h头文件中声明的opendir(),readdir()函数;

intmain(intargc,char*argv[])
{
DIR*directory_pointer;
structdirent*entry;

if((directory_pointer=opendir("d:\XL"))==NULL)
printf("Erroropening ");
else
{
while((entry=readdir(directory_pointer))!=NULL)
{
printf("%s ",entry->d_name);
}
closedir(directory_pointer);

}

system("PAUSE");
return0;
}

3、如果没有dirent.h,可以使用io.h头文件中声明的_findfirst(),_findnext()函数;

示例代码:

intmain(intargc,char*argv[])
{
longfile;
struct_finddata_tfind;

_chdir("d:\");
if((file=_findfirst("*.*",&find))==-1L)
{
printf("空白! ");
exit(0);
}
printf("%s ",find.name);
while(_findnext(file,&find)==0)
{
printf("%s ",find.name);
}
_findclose(file);

system("PAUSE");
return0;
}

⑻ C语言 读取文件名字

void FindMp3File(strDirectory)
{
CFileFind finder;
if(finder.FindFile(*.*))
{
BOOL bWorking=FALSE;
bWorking=finder.FindNextFile();
while(1)
{
if (finder.IsDots())
{
if(bWorking)
{
bWorking=finder.FindNextFile();
continue;
}
else
{
return;
}
}
else if(finder.IsDirectory())
{
FindMp3File(finder.GetFilePath());
}
else if(finder.GetFileName().Right(3)=="")
{
//Get a Mp3 File;
//You Can Do Something Hear;
if(bWorking)
{
bWorking=finder.FindNextFile();
}
else
{
return;
}
}
}
}
}

⑼ 在c语言中读写文件如何查找特定名称的文件

打开文件,遍历文件内容然后一个一个匹配查找就好了。专

阅读全文

与c过滤文件类型读取文件名相关的资料

热点内容
饮水机是由什么材质做成 浏览:72
污水接口错口怎么处理 浏览:503
孩子吃了除垢剂 浏览:448
诸城污水处理项目 浏览:649
博世净水器怎么换滤芯 浏览:349
重汽豪沃轻卡多少公里换空气滤芯 浏览:233
派瑞的空气净化器怎么样 浏览:398
空气滤芯什么牌子好一点 浏览:904
废水石油类污染物有哪些 浏览:820
氯离子氧化反渗透膜 浏览:605
色粉粘在树脂怎样去除 浏览:401
河北省环境污水事件 浏览:205
饮水机怎么放水桶安全 浏览:638
山东四海水处理设备有限公司招聘 浏览:740
全自动玻璃蒸馏器 浏览:531
用蒸馏法分离乙酸和二氯甲烷 浏览:815
ab法污水处理实验 浏览:833
污水处理方案设计基本资料 浏览:625
ro膜为什么横着放 浏览:415
水蒸气蒸馏分离环己酮和水 浏览:598