33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <io.h>
#include <direct.h>
#include <string>
#include <vector>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <locale>
using namespace std;
void getFiles( string, vector<wstring>& );
int main() {
vector<wstring> files;
getFiles( ".", files );
wfstream file;
file.open("name.txt",ofstream::out);
for (int j=0; j<files.size(); ++j) {
file<<files[j]<<endl;
}
file.close();
system("pause");
return 0;
}
void getFiles( string path, vector<wstring>& files ) {
long hFile = 0;
struct _wfinddata_t fileinfo;
string p;
if ((hFile = _wfindfirst(L"*",&fileinfo)) != -1) {
do {
if ((fileinfo.attrib & _A_SUBDIR)) {
if (wcscmp(fileinfo.name,L".") != 0 && wcscmp(fileinfo.name,L"..") != 0) {
files.push_back(fileinfo.name );
wcout<<fileinfo.name<<endl;
}
}
} while (_wfindnext( hFile, &fileinfo ) == 0);
_findclose(hFile);
}
}