Ⅰ 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);
}
}
}
}