導航:首頁 > 文件類型 > 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獲取當前文件名相關的資料

熱點內容
天津編程考試哪裡好 瀏覽:792
蘋果手機更新系統後系統文件過大 瀏覽:810
js的事件有什麼區別 瀏覽:763
圖片中植入程序 瀏覽:832
數控機床編程哪裡能學 瀏覽:110
網頁源代碼的視頻 瀏覽:684
java獲取button的名字 瀏覽:64
ps人物彩繪攝影教程 瀏覽:70
c獲取當前文件名 瀏覽:212
3dmax9怎麼打開文件 瀏覽:965
iphone刪除的app還在 瀏覽:100
ug編程怎麼復制圖層 瀏覽:980
keil中自己編寫c語言頭文件 瀏覽:261
xp換成win7後文件只讀 瀏覽:279
檢測數據是什麼 瀏覽:151
如何編程製造游戲 瀏覽:791
電腦文件快捷鍵 瀏覽:793
看在一起多久的app 瀏覽:953
公文中什麼時候有文件 瀏覽:668
小孩編程有什麼語言 瀏覽:373

友情鏈接