Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

this is a linux one

Posted on 2000-04-07
4
Medium Priority
?
219 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 30 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

971 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