Catalogue and subcatalog files
-
We need to find all the files on the catalogue and all the subcategories and copy the Dir catalogue.
How do you do that?
-
For reading catalogues in standard library C, there are functions described in the headline file
dirent.h
♪ The next fragment makes one catalogue look.#include <dirent.h>
...
DIR *dp; struct dirent *ep; dp = opendir(path); if (!dp) { /* Ошибка открытия, возможно нет прав, или это не каталог, или что-то ещё, можно уточнить через errno */ ... } while ((ep = readdir(dp))) { if (!strcmp(ep->d_name, "..") || !strcmp(ep->d_name, ".")) continue; /* делаем с именем что-то дальше */ ... } closedir(dp);
Before copying, it is worth checking on different situations, for example, if the appointment file already exists and this is a reference to the original file, or if the original file is a device, fifo is a file, a juice or a symbolic reference.
All these checks make the Utilities.
cp
but with a surround, she's digging a tree of catalogues into a tree, not one catalogue. If you want to write a copy on your own, you need to get a look at it. http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/cp.c;h=8fb5e444fbaf529c19b3d9ff92c3928302e39118;hb=master or with a simpler option https://busybox.net/source.html ♪The same can be done with a utilitate tour.
find
♪