wrote CLI in C++ to sort files. it's very simple, just download and use. if you a photographer, video editor or just need to sort some files, you welcome (link in post)
simple sorting programm for Linux
https://github.com/metw0/qsort
https://github.com/metw0/qsort
wrote CLI in C++ to sort files. it's very simple, just download and use. if you a photographer, video editor or just need to sort some files, you welcome (link in post)
11 Comments
thenextguy@sh.itjust.works · 11 pts · 5d
I don't think it is at all clear what this does.
It sorts files how?
bobo@lemmy.ml · 4 pts · 4d
It doesn't sort them in the programming sense, it's just moving files to another directory based on the filename
is equivalent to
MonkderVierte@lemmy.zip · 3 pts · 4d
Btw, you should not pipe ls. It's unsafe.
fruitcantfly@programming.dev · 8 pts · 4d
lscan be piped safely if you use--zero:While the above is a pretty silly example, one reason why you might want to do this is that
xargshas a-P/--max-procsargument, that runs N commands in parallel. So you could do something like the following to gzip four files in parallel:This is a bit simpler than using the equivalent
MonkderVierte@lemmy.zip · 1 pts · 3d
While the later is more reliably available. Use this in scripts you distribute. And also finds
-execinstead of|xargs.fruitcantfly@programming.dev · 2 pts · 3d
Both
findandxargsare POSIX commands, so there's something wrong with your OS if you are missing either, andfinddoes not have an equivalent of-P. Granted,-Pis an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox'sxargscommands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OSbobo@lemmy.ml · 4 pts · 4d
Source? I tried searching for it and found nothing.
BB_C@programming.dev · 7 pts · 4d
I think the other user meant that
lsoutput is not supposed to be treated as parsable, because the tool doesn't offer any guarantees in that regards.Shells have built-in support for globbing files anyway.
xargsis also not needed. If someone is allergic to using a shellforloop,findalways had-execwith;instead+which wouldn't trip on too many arguments.metw0@lemmy.world · 3 pts · 5d
this is just a practice project, I shared it just so other people could take a look. you can see how it sorts files by checking out the repository
fruitcantfly@programming.dev · 7 pts · 4d
Here are a few random thoughts based on skimming the source:
-Weverything. Many of the warnings it enables are not very useful, and you are going to get a lot of them. And if you enable warnings, then fix them, or you'll just miss it when your changes cause new warnings.typeis not on of the expected values. That is undefined behavior. One simple way to avoid this, is to move the commonreturnout of the ifs.const std::string typeargument in the above functions should be enums, since you are just checking againts one of three fixed values ("name","ext", and"date").const std::stringargument. Either use a const reference (const std::string&) or a string_view (const std::string_view). The latter has the advantage that it doesn't create a newstd::stringif you call the function with a C-string and it can be sliced cheaply.const std::string &df = df_str;in a couple of places, wheredf_stris astd::stringpassed by value. That is of course utterly pointless, and you should simply changedf_strto be passed by const reference or as a string view.mainwith anintreturn type, but usestd::exitto exit the function. Thosestd::exitcalls could all be replaced withreturn, which does the same thing inmain.check_typeyou perform two checks (saved asstarts_with_dotandhas_dash), that are not used ifname == "name".check_existswould expect it to create a directory, so it should be renamed to something more descriptive. It is also redundant, since you already check that the directory exists inmain.cppviais_directory, but unlike that checkcheck_existsdoesn't actually verify that the path is a directory.is_foundedis Engrishmetw0@lemmy.world · 2 pts · 22h
thanks for the detailed feedback, I appreciate it