question attached

1 answer below »
Answered 10 days AfterOct 05, 2021

Answer To: question attached

Darshan answered on Oct 16 2021
134 Votes
#include
#include
#include
#include
#include
#include
#include
#include
int move(int ac, cha
r* av[]);
void formatError();
int ls_command();
int mv_command();
int tar_command();
int cd_command();
int search_command();
DIR *dp;
struct dirent *p;
FILE *fptr;
void goodbye(int n)
{
    printf("********GOOD BYE********\n");
    exit(0);
}
int main()
{
    signal(SIGINT,goodbye);
    int input;
fptr = fopen("logerr.txt", "w");
    while(1)
    {
        // Take input from user
        printf("\n\nPlease Select Option from 1 to 6\n");
        printf("1. List the files in the current directory\n");
        printf("2. move files to directory\n");
        printf("3. tar file creation \n");
        printf("4. navigate to another directory\n");
        printf("5. search/list only empty files/directories\n");
        printf("6. Exit\n");
        scanf("%d",&input);    
        switch(input)
        {
                case 1:
                        ls_command();
                break;
        
                case 2:
                        mv_command();
                break;    
        
                case 3:
                        tar_command();
                break;
                case 4:
                        cd_command();
                break;
                case 5:
                        search_command();
                break;
                case 6:
                        exit(0);
                break;
                
                default:
                printf("Wrong input enter. Please select proper option:\n");
                fclose(fptr);
                exit(0);
                return 0;
                break;
        }
    }
    fclose(fptr);
    return 0;
}
int ls_command()
{
    dp=opendir(".");
        
    if(dp==0)
    {
        perror("opendir");    
        return 0;
    }
printf("\nList the files in the current directory:\n");
        while(p=readdir(dp))
            if(p->d_name[0]!='.')
                printf("%s\n",p->d_name);
            printf("\n\n");
return 0;            
}
int mv_command()
{    
    printf("Provide a directory name and then a series of filesname to move\n");
char string[50];
    int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here