導航:首頁 > 文件類型 > c獲取當前文件名

c獲取當前文件名

發布時間:2025-10-19 08:18:24

Ⅰ 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語言如何獲得文件當前路徑

C語言里
在main函數來的第二個參數裡面,自
保存著當前程序運行的目錄
也就是argv[0]
main( int argc, char *argv[])
{
printf("%s ", argv[0] );
}
就是文件當前所在位置
不過需要注意的一點是
這個路徑裡面保存了當前文件的文件名
如果你只是需要路徑的話還需要自己操作一下

main(int a,char *c[])
{
char s[100];
int i;
//把路徑保存到字元串s里
strcpy(s,c[0]);
for(i=strlen(s); i>0 ; i--)
if( s[i] == '\\')
{
s[i]='\0';
break;
}
//找到最後一個 \ 並刪除之後的內容
//最後輸出的s,就是當前文件的路徑了
puts(s);
}

Ⅲ C/C++怎樣將獲取文件的擴展名和文件名

#include <string.h>
#include <stdio.h>
int main()
{
char filename[0]="text.txt" ;
char *ext=strrchr(filename,'.');
if (ext)
{
*ext='\0';
ext++;
}
printf("name=%s\n", filename);
printf("ext-name=%s\n", ext );
return 0;
}

Ⅳ C++中如何從路徑字元串中獲取文件名!

C風格:

char*p=strrchr(path.c_str(),'/')

p是path里最後一個'/'的地址。然後

strings(p+1);

,內s就是"world.shp"了。


C++風格:

intpos=path.find_last_of('/');

pos就是最後一個'/'的下標容。

然後

strings(path.substr(pos+1));

s就是"world.shp"了。

Ⅳ C# 遍歷文件夾下所有子文件夾中的文件,得到文件名

假設a文件夾在F盤下,代碼如下。將文件名輸出到一個ListBox中
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
DirectoryInfo theFolder = new DirectoryInfo(@"F:\a\");
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
//遍歷文件夾
foreach (DirectoryInfo NextFolder in dirInfo)
{
// this.listBox1.Items.Add(NextFolder.Name);
FileInfo[] fileInfo = NextFolder.GetFiles();
foreach (FileInfo NextFile in fileInfo) //遍歷文件
this.listBox2.Items.Add(NextFile.Name);
}

}
}
}

閱讀全文

與c獲取當前文件名相關的資料

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接