Lab6_Ex10.c - #include#include#include#include#include#include <stdio.h> <sys\/stat.h> <stdlib.h> <unistd.h> <string.h> <sys\/sysmacros.h> void

Lab6_Ex10.c -...

This preview shows page 1 - 2 out of 2 pages.

#include <stdio.h>#include <sys/stat.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/sysmacros.h>void fileInfo(char const filename[]);int main(int argc, char *argv[]){int i;if(argc > 1){ //Else if arguments >= 1, then go through each argument and display files//printf("There are %d command line arguments.\n", argc);for (i=1; i < argc; ++i){printf("\n*************************************************");printf("\n\nArgument number: %d = '%s' \n\n", i, argv[i]);printf("*************************************************\n");//If File exists and can be accessed then process the file informationif(access(argv[i], F_OK ) != -1 ) {fileInfo(argv[i]); //Process file information} else { //File doesn't exist then print the errorprintf("\nFile doesn't exist!\n");}}}return 0;}void fileInfo(char const filename[]){struct stat fileInfo; //Stat struct that holds all file informationif(stat(filename,&fileInfo) == -1){ //If cannot stat the file then print errorprintf("Error! Cannot get information of file!\n");}printf("\nFile type: ");//Finding type of file that it is using st_modeswitch (fileInfo.st_mode & S_IFMT) {case S_IFREG: printf("Regular file\n"); break; //If it's a Regular file
Background image
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture