本文主要是介绍一个关于读取指定路径下文件名称的小工具(C++),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include<iostream>
#include<io.h>
#include <fstream>
using namespace std;
int main(){
_finddata_t file;
long lf;
ofstream ofs; //提供写文件的功能
ofs.open("d:\\outFile.txt",ios::trunc); //trunc打开文件时,清空已存在的文件流,若不存在此文件则先创建
char nameStart[] = "{type:'image', src:\"";
char namEnd[] = "\"},";
cout<<"*****************************************************"<<"\n\n";
cout<<"生成txt文件路径:"<<"d:\\\\outFile.txt"<<"\n\n";
cout<<"*****************************************************"<<"\n\n";
cout<<"输入检索路径格式如下:"<<"\n";
cout<<"F:\\\\MyFile\\\\Published-HTML5\\\\mainframe\\\\*.png"<<"\n\n";
cout<<"*****************************************************"<<"\n";
cout<<"input path :"<<endl;
char a[200];
cin.get(a,200);
//cin>>"文件路径:";
//输入文件夹路径
if((lf = _findfirst(a, &file))==-1)
cout<<"Not Found!"<<endl;
else{
//输出文件名
cout<<"file name list:"<<endl;
while(_findnext( lf, &file)==0){
cout<<file.name<<endl;
ofs<<nameStart<<file.name<<namEnd<<"\n";
}
}
_findclose(lf);
//return 0;
}
这篇关于一个关于读取指定路径下文件名称的小工具(C++)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!