mirror of
https://github.com/mrfluffy-dev/fsorter.git
synced 2026-01-17 02:50:33 +00:00
make type, extentions and paths dynamic
This commit is contained in:
103
main.cpp
103
main.cpp
@@ -4,24 +4,25 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
//#include <bits/stdc++.h>
|
//#include <bits/stdc++.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
std::string musicTypes[] = {".mp3",".wav"};
|
||||||
|
std::string pictureType[] = {".jpg","jpeg","png"};
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
std::string settingsPath = "settings.conf";
|
std::string settingsPath = "settings.conf";
|
||||||
class paths{
|
std::string home = getenv("HOME");
|
||||||
|
class typeAndPaths{
|
||||||
public:
|
public:
|
||||||
std::string Picturs;
|
std::string type;
|
||||||
std::string Music;
|
std::string path;
|
||||||
std::string Vidios;
|
std::vector<std::string> extentions;
|
||||||
std::string Arcives;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void writeSettins()
|
void writeSettins()
|
||||||
{
|
{
|
||||||
std::ofstream settings(settingsPath);
|
std::ofstream settings(settingsPath);
|
||||||
settings << "Picture=\n$HOME/Pictures" << std::endl;
|
settings << "Picture=\n"+ home +"/Pictures\n.jpg,.jpeg,.png" << std::endl;
|
||||||
settings << "Music=\n$HOME/Music" << std::endl;
|
settings << "Music=\n"+home+"/Music\n.mp3,.wav" << std::endl;
|
||||||
settings << "Video=\n$HOME/Videos" << std::endl;
|
settings << "Video=\n"+home+"/Videos\n.mp4" << std::endl;
|
||||||
settings << "Arcive=\n$HOME/Documents/Compressed" << std::endl;
|
settings << "Arcive=\n"+home+"/Documents/Compressed\n.zip,.rar,.7z" << std::endl;
|
||||||
settings.close();
|
settings.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,39 +43,81 @@ std::vector<std::string> readSettings()
|
|||||||
listOfPaths.push_back(setting);
|
listOfPaths.push_back(setting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
settings.close();
|
||||||
return listOfPaths;
|
return listOfPaths;
|
||||||
}
|
}
|
||||||
paths declarePaths(std::vector<std::string> listOfPaths)
|
std::vector<typeAndPaths> declarePaths(std::vector<std::string> listOfPaths)
|
||||||
{
|
{
|
||||||
paths Paths;
|
typeAndPaths Paths;
|
||||||
for (int i = 0; i < listOfPaths.size(); i+=2)
|
std::vector<typeAndPaths> paths;
|
||||||
|
for (int i = 0; i < listOfPaths.size(); i+=3)
|
||||||
{
|
{
|
||||||
listOfPaths[i].pop_back();
|
listOfPaths[i].pop_back();
|
||||||
std::string type = listOfPaths[i];
|
Paths.type = listOfPaths[i];
|
||||||
std::string path = listOfPaths[i+1];
|
Paths.path = listOfPaths[i+1];
|
||||||
if(type == "Picture")
|
std::string stringExtentions = listOfPaths[i+2];
|
||||||
|
std::vector<std::string> extentions;
|
||||||
|
char temp;
|
||||||
|
std::string tempWord;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < stringExtentions.size(); i++) {
|
||||||
|
temp = stringExtentions[i];
|
||||||
|
if(temp != ',')
|
||||||
{
|
{
|
||||||
Paths.Picturs = path;
|
|
||||||
|
tempWord.push_back(temp);
|
||||||
}
|
}
|
||||||
else if (type == "Music")
|
else
|
||||||
{
|
{
|
||||||
Paths.Music = path;
|
extentions.push_back(tempWord);
|
||||||
}
|
tempWord = "";
|
||||||
else if (type == "Video")
|
counter++;
|
||||||
{
|
|
||||||
Paths.Vidios = path;
|
|
||||||
}
|
|
||||||
else if (type == "Arcive")
|
|
||||||
{
|
|
||||||
Paths.Arcives = path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Paths;
|
Paths.extentions = extentions;
|
||||||
|
paths.push_back(Paths);
|
||||||
|
}
|
||||||
|
return paths;
|
||||||
}
|
}
|
||||||
|
void checkSettingsPaths(std::vector<typeAndPaths> Paths)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Paths.size(); i++)
|
||||||
|
{
|
||||||
|
if(fs::exists(Paths[i].path))
|
||||||
|
{
|
||||||
|
std::cout << "Yes\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool valid = false;
|
||||||
|
while (!valid) {
|
||||||
|
char awnser;
|
||||||
|
std::cout << "would you like to create y=yes, n=no : " << Paths[i].path << "\t";
|
||||||
|
std::cin >> awnser;
|
||||||
|
std::cout << '\n';
|
||||||
|
if(tolower(awnser) == 'y')
|
||||||
|
{
|
||||||
|
fs::create_directory(Paths[i].path);
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
else if (tolower(awnser) == 'n')
|
||||||
|
{
|
||||||
|
std::cout << "Directory was not created\n";
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "pleas provide valid awnser" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::vector<std::string> listOfPaths = readSettings();
|
std::vector<std::string> listOfPaths = readSettings();
|
||||||
paths Paths = declarePaths(listOfPaths);
|
std::vector<typeAndPaths> Paths = declarePaths(listOfPaths);
|
||||||
std::cout << Paths.Picturs << std::endl;
|
checkSettingsPaths(Paths);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user