I don't think it is at all clear what this does.
It sorts files how?
I don't think it is at all clear what this does.
It sorts files how?
It doesn't sort them in the programming sense, it's just moving files to another directory based on the filename
qsort -w /home/user/Documents -t ext --df .txt
is equivalent to
ls *.txt | xargs -I {} mv {} /home/user/Documents
Btw, you should not pipe ls. It's unsafe.
ls can be piped safely if you use --zero:
ls --zero *.txt | xargs --null -I {} mv {} /home/user/Documents
While the above is a pretty silly example, one reason why you might want to do this is that xargs has a -P/--max-procs argument, that runs N commands in parallel. So you could do something like the following to gzip four files in parallel:
ls --zero *.txt | xargs --null -n1 -P4 gzip
This is a bit simpler than using the equivalent
find . -maxdepth 1 -name '*.txt' -print0 | xargs --null -n1 -P4 gzip
While the later is more reliably available. Use this in scripts you distribute. And also finds -exec instead of |xargs.
Both find and xargs are POSIX commands, so there's something wrong with your OS if you are missing either, and find does not have an equivalent of -P. Granted, -P is an extension, but it is supported by GNU's, OpenBSD's, FreeBSD's, and BusyBox's xargs commands, and probably also by others, so it is reasonable to assume that it is available unless you are targeting some obscure OS
Source? I tried searching for it and found nothing.
I think the other user meant that ls output 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. xargs is also not needed. If someone is allergic to using a shell for loop, find always had -exec with ; instead + which wouldn't trip on too many arguments.
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
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.type is not on of the expected values. That is undefined behavior. One simple way to avoid this, is to move the common return out of the ifs.const std::string type argument in the above functions should be enums, since you are just checking againts one of three fixed values ("name", "ext", and "date").const std::string argument. 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 new std::string if 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, where df_str is a std::string passed by value. That is of course utterly pointless, and you should simply change df_str to be passed by const reference or as a string view.main with an int return type, but use std::exit to exit the function. Those std::exit calls could all be replaced with return, which does the same thing in main.check_type you perform two checks (saved as starts_with_dot and has_dash), that are not used if name == "name".check_exists would 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 in main.cpp via is_directory, but unlike that check check_exists doesn't actually verify that the path is a directory.is_founded is Engrishthanks for the detailed feedback, I appreciate it
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev