Solved

this is a linux one

Posted on 2000-04-07
4
197 Views
Last Modified: 2010-04-15
i have to write a program that will look in a directory and count all the files that hte read permitions for the group and anyone. the result should be in a file (formatted text).
0
Comment
Question by:kplonk
  • 2
4 Comments
 
LVL 2

Expert Comment

by:munsie
ID: 2695222
if your looking for someone to write your school assignment, then you're looking in the wrong place.

for a quick pointer, read the man page for opendir() and stat().

dennis
0
 

Author Comment

by:kplonk
ID: 2695271
that is not what i wnat all i need to know is hoe to get the informaton oh the access writes to a file. thanks, also the dta type needed to hold this would also be nice.
0
 
LVL 2

Expert Comment

by:munsie
ID: 2695404
ok, in my original comment i said to look at the opendir() and stat() man pages.  These two calls (and related calls) have everything you need to do what you described.  The opendir() call allows you to find the name and other information about every file in a directory.  The stat() call will give you any other information you need.

dennis
0
 

Accepted Solution

by:
SkAtAn earned 10 total points
ID: 2698130
This one is from "beginning Linux Programming" .. I am sure you will be abel to do something with it.

/*  We start with the appropriate headers and then a function, printdir,
    which prints out the current directory.
    It will recurse for subdirectories, using the depth parameter is used for indentation.  */

#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>

void printdir(char *dir, int depth)
{
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;

    if((dp = opendir(dir)) == NULL) {
        fprintf(stderr,"cannot open directory: %s\n", dir);
        return;
    }
    chdir(dir);
    while((entry = readdir(dp)) != NULL) {
        lstat(entry->d_name,&statbuf);
        if(S_ISDIR(statbuf.st_mode)) {
            /* Found a directory, but ignore . and .. */
            if(strcmp(".",entry->d_name) == 0 ||
                strcmp("..",entry->d_name) == 0)
                continue;
            printf("%*s%s/\n",depth,"",entry->d_name);
            /* Recurse at a new indent level */
            printdir(entry->d_name,depth+4);
        }
        else printf("%*s%s\n",depth,"",entry->d_name);
    }
    chdir("..");
    closedir(dp);
}

/*  Now we move onto the main function.  */


int main(int argc, char* argv[])
{
    char *topdir, pwd[2]=".";
    if (argc != 2)
        topdir=pwd;
    else
        topdir=argv[1];

    printf("Directory scan of %s\n",topdir);
    printdir(topdir,0);
    printf("done.\n");  

    exit(0);
}
         
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question