您的位置:首页 > 编程语言 > C语言/C++

一个关于读取指定路径下文件名称的小工具(C++)

2014-06-26 15:40 411 查看

#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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐