Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by sidjey ( 15 years ago )
// открываем каталог, если возможно
    DIR *dir = opendir(argv[1]);
    if (dir == NULL)
    {
        printf("Error opening %s: %s", argv[1]);
        return 0;
    }
    
    struct dirent entry;
    struct dirent *entryPtr = NULL;
    int retval = 0;
    int count = 0;
    
    retval = readdir_r(dir, &entry;, &entryPtr;);
    while (entryPtr != NULL)
    {
        struct stat entryInfo;

        // пропускаем каталоги . и ..
        if ( (strncmp(entry.d_name, ".", PATH_MAX) == 0) ||
             (strncmp(entry.d_name, "..", PATH_MAX) == 0) )
        {
            retval = readdir_r(dir, &entry;, &entryPtr;);
            continue;
        }
        
        char pathName[PATH_MAX + 1];
        strncpy(pathName, argv[1], PATH_MAX);
        strncat(pathName, "/", PATH_MAX);
        strncat(pathName, entry.d_name, PATH_MAX);

        if (lstat(pathName, &entryInfo;) == 0)
        {
            // вызов stat() был успешным продолжаем
            //count++;

            if (S_ISDIR(entryInfo.st_mode))
            {
                // каталог
                // тут как бы надо делать форк и обрабатывать рекурсивно каталог
                // происходит разветвление на 2 процесса
                int descriptor[2];
                pid_t pid;
                //pipe(descriptor);
                pid = fork();
                if (pid > 0)
                {
                    // родительский процесс
                }
                else
                {
                    // дочерний процесс
                    
                }
            }
            else if (S_ISREG(entryInfo.st_mode))
            {
                // обычный файл
                // бла - бла - бла
            }
        }

 

Revise this Paste

Your Name: Code Language: