-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp3ListToTXT.cpp
More file actions
66 lines (48 loc) · 1.33 KB
/
Copy pathmp3ListToTXT.cpp
File metadata and controls
66 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include <string>
#include <fstream> // text file openings
#include <dirent.h>
#include <cstdlib>
using namespace std;
int main(){
//open file 1 = filename
ofstream fileSongName;
fileSongName.open("songnames.txt");
//Keeps a list of all the music files in the directory
vector <string> dirList;
//
DIR *dir;
struct dirent *ent;
if ((dir = opendir (".")) != NULL) {
/* store all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
//printf ("%s\n", ent->d_name);
string fname;
fname = ent->d_name;
int strlength = fname.length();
//Check for filename to be longer than 3
//there are files called . and .. that we should skip
//if the file is a .mp3 we add it to music file vector, dirList
if (strlength > 3)
{
string fileType;
fileType = fname.substr(strlength-3,3);
if (fileType == "mp3")
{
dirList.push_back(fname);
}
}
}
closedir (dir);
} else {
/* could not open directory */
perror ("");
return EXIT_FAILURE;
}
for (int i = 0; i < dirList.size(); i++)
{
fileSongName << dirList[i] << endl;
}
return 0;
}