導航:首頁 > 凈水問答 > 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過濾文件類型讀取文件名相關的資料

熱點內容
家用凈化器怎麼拆除 瀏覽:190
污水井蓋板鋼筋怎麼綁 瀏覽:651
小愛凈化器怎麼樣 瀏覽:283
2018展望水處理項目 瀏覽:74
污水處理後置投葯除磷 瀏覽:535
機油濾芯和機油機濾有什麼不同 瀏覽:133
河南雪峰水處理設備有限公司 瀏覽:967
麻將房凈化器起到什麼樣的作用 瀏覽:766
污水設計管段如何劃分 瀏覽:534
污水管落在客廳中間怎麼處理 瀏覽:490
磁化水機怎麼換濾芯 瀏覽:461
陶氏RO膜使用三年後脫鹽率 瀏覽:537
沒有蒸餾水怎麼辦葯 瀏覽:574
塑料樹脂衣櫃好用嗎 瀏覽:465
海爾空氣凈化器怎麼拆卸 瀏覽:836
鄠邑區秦渡鎮污水處理 瀏覽:124
怎麼樣安裝濾芯 瀏覽:620
污水處理廠糞大腸桿菌 瀏覽:93
汽車空調濾芯要怎麼選 瀏覽:895
高腳單相小污水泵葉子 瀏覽:961