find the file's attribute....

0 MARTIN WANG · October 11, 2014
Does anyone know how to recognize file's attribute?
because I'd like to write a program to recognize different file's attribute and print file's name out to .txt file.
for example,read the all the file inside the document and only print .mp3 type to txt file.

the question is I have no idea to recognize .mp3 type to txt file.
my program is just print all the file's name to txt file.
here is my coding....
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>

using namespace std;
ifstream& open_file(ifstream &in,const string &file){
    in.close();
    in.clear();
    in.open(file.c_str());
    return in;
}


int getdir(string dir, vector<string> &files){
    DIR *dp;
    struct dirent *dirp;
    if((dp = opendir(dir.c_str())) == NULL){
        cout << "Error(" << errno << ") opening " << dir << endl;
        return errno;
    }
    while((dirp = readdir(dp)) != NULL){
        files.push_back(string(dirp->d_name));//put files inside vector
    }
    closedir(dp);
    return 0;
}

int main(){
    string dir = string("D:\\Music"); //document and files location
    vector<string> files = vector<string>();
    getdir(dir, files);
    //output document

    ofstream output;
   if(!outputfile(output,"mp3file.txt")){ //output txt file's name
    cerr << "error";
   }
    for(int i=0; i<files.size(); i++){
        output << files << endl;
        cout <<files << endl;
    }
    system("pause");
    return 0;
}





can anyone give me some hint?thanks

Post a Reply

Replies

Oldest  Newest  Rating
0 MARTIN WANG · October 11, 2014
thanks!!! I think i know how to do it:)
the big mistake is i think mp3 is a file attribute....
  • 1

C++

107,195 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator