Support directories (instead of crashing)

This commit is contained in:
stefan.haustein@gmail.com 2018-07-29 23:55:46 +02:00
parent 7eee8d8bbb
commit 1ce1732e68
2 changed files with 13 additions and 3 deletions

View file

@ -1,10 +1,10 @@
default: tiv
tiv.o: tiv.cpp CImg.h
g++ -std=c++11 -Wall -fexceptions -O2 -c tiv.cpp -o tiv.o
g++ -std=c++17 -Wall -fpermissive -fexceptions -O2 -c tiv.cpp -o tiv.o
tiv : tiv.o
g++ tiv.o -o tiv -pthread -s
g++ tiv.o -o tiv -lstdc++fs -pthread -s
install: tiv
cp tiv /usr/local/bin/tiv

View file

@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <sys/ioctl.h>
#include <experimental/filesystem>
#define cimg_display 0
#include "CImg.h"
@ -434,10 +435,19 @@ int main(int argc, char* argv[]) {
emit_usage();
} else if (arg[0] == '-') {
std::cerr << "Unrecognized argument: " << arg << std::endl;
} else {
if (std::experimental::filesystem::is_directory(arg)) {
for (auto & p : std::experimental::filesystem::directory_iterator(arg)) {
if (std::experimental::filesystem::is_regular_file(p.path())) {
file_names.push_back(p.path().string());
}
}
} else {
file_names.push_back(arg);
}
}
}
if (mode == FULL_SIZE || (mode == AUTO && file_names.size() == 1)) {
for (unsigned int i = 0; i < file_names.size(); i++) {