导航:首页 > 文件类型 > 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

友情链接