Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <pwd.h> // necesar pentru functia getpwuid
- #include <grp.h> // necesar pentru functia getgrgid
- #include <limits.h> // necesar pentru PATH_MAX
- void cauta(char *cale);
- int main(int argc, char **argv)
- {
- struct stat st;
- if (argc < 2)
- {
- printf("Introdu numele directorului in care vrei sa stergi link-urile sym nefolositoare !\n");
- exit(1);
- }
- if (0 != stat(argv[1], &st))
- {
- fprintf(stderr, "Eroare la stat pentru %s .\t", ".");
- perror("Cauza este");
- exit(2);
- }
- cauta(".");
- }
- int isFolder(char *cale);
- void cauta(char *cale)
- {
- DIR *dir;
- struct stat st;
- struct dirent *de;
- char caleNoua[PATH_MAX];
- int verifica;
- verifica = isFolder(cale);
- if (verifica == 0)
- {
- return;
- }
- else
- {
- if (NULL == (dir = opendir(cale)))
- {
- printf("Eroare deschidere director %s .\n", cale);
- return;
- }
- else
- {
- while (NULL != (de = readdir(dir)))
- {
- if (strcmp(de->d_name, ".") && strcmp(de->d_name, ".."))
- {
- sprintf(caleNoua, "%s/%s", cale, de->d_name);
- if (lstat(caleNoua, &st) != 0)
- printf("Eroare la lstat pentru %s.\n", caleNoua);
- else
- {
- int ac = access(caleNoua, F_OK);
- if (ac == -1 && ((st.st_mode & __S_IFMT) == __S_IFLNK))
- unlink(caleNoua);
- }
- cauta(caleNoua);
- }
- }
- }
- }
- }
- int isFolder(char *cale)
- {
- int ok = 0;
- struct stat st;
- if (stat(cale, &st) != 0)
- {
- printf("Eroare la stat pentru %s . \n", cale);
- return 0;
- }
- if ((st.st_mode & __S_IFMT) == __S_IFDIR)
- ok = 1;
- return ok;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement