I use glib in my application and I see that glib has convenient wrappers for C remove , unlink and rmdir . But they only work on one file or directory at a time.
As far as I understand, neither the C standard nor glib includes any recursive directory management function. I also do not see a specific way to delete the entire directory tree at once, as in rm -rf .
Why am I doing this, I don’t care about any complications, such as permissions, symbolic tree references (infinite recursion), or anything that excludes very naive implementations ... so I would not mind writing my own function for it.
However, I am curious that this functionality is already somewhere in the standard gtk or glib libraries (or in some other reusable C library) already, and I just didn’t stumble upon it. This topic generates a lot of false results.
Otherwise, my plan is to use this type of algorithm:
dir_walk(char* path, void* callback(char*) { if(is_dir(path) && has_entries(path)) { entries = get_entries(path); for(entry in intries) { dir_walk(entry, callback); } } else { callback(path) } } dir_walk("/home/user/trash", remove);
Obviously, I will create some error handling, etc., to interrupt the process as soon as a fatal error occurs.
c glib gtk
mlibby
source share