Question

Need Help doing this in C Please Help

Search or enter website name Apple Disney ESPN Yahoo Student Courses Online Storage E-Portfolio organizations & Clubs Help NAME dirp directory processing tool SYNOPSIS dirp OPTION EILE CEILEJ DESCRIPTION Allows the user to manipulate directory entries (files or other directories) -c creates a directory with permissions rwxr-r-- -d deletes a directory entry renames a directory entry EXAMPLES rp -c newdir new directory named newdir is created dirp -d newdir new dir is deleted. If newdir doesnt exist, an appropriate error message is displayed dirp-r oldname newname A directory entry named oldname is renamed to newname. dirp synopsis message displayed NOTES Does not use amy C++ specific code. Does not prompt the user in any way. Does not perform input validation. HINTS There are a couple of different ways to remove directoryentries. Use whichever one you like.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code :

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main (int argc, char **argv)
{  
   int results;  
   if(argc >= 3)
   {
       //("%d",argc);
       //printf("%s",argv[1]);
       if (argv[1][1] == 'r' && argc == 4)
           results = rename(argv[2],argv[3]);
       else if(argv[1][1] == 'c')
           results = mkdir(argv[2],0744);
       else if(argv[1][1] == 'd')
           results = remove(argv[2]);

   }
   else if(argc == 1)
   {
       printf("Usage : dirp OPTION FILE [FILE]\n");
   }
   return 0;
}

Output :

vivek@vivek-VirtualBox: $ ls -lrt I tail -5 rwxr-xr-x 1 vivek vivek -rwxr-xr-x 1 vivek vivek 133 Apr 27 09:58 log_users.sh rw-rr1 vivek vivek 578 Apr 27 09:58 users.log -rw-rr 1 vivek vivek 505 Apr 28 09:13 dirp.c rwxr-xr-x 1 vivek vivek 8544 Apr 28 09:14 dirp vivek@vivek-VirtualBox $ ./dirp c vik vivek@vivek-VirtualBox: $ ls lrt I tail 5 -rwxr-xr-x 1 vivek vivek 133 Apr 27 09:58 log_users.sh -rw-r-r1 vivek vivek 578 Apr 27 09:58 users.log -rw-r-r 1 vivek vivek 505 Apr 28 09:13 dirp.c rwxr-xr-x 1 vivek vivek 8544 Apr 28 09:14 dirp drwxr-r2 vivek vivek 4096 Apr 28 09:15 vik vivek@vivek-VirtualBox $ ./dirp r vik viv vivek@vivek-VirtualBox: $ ls -lrt I tail -5 -rwxr-xr-? 1 vivek vivek 133 Apr 27 09:58 log-users. sh -rw-r-r 1 vivek vivek 578 Apr 27 09:58 users.log -rw-rr1 vivek vivek 505 Apr 28 09:13 dirp.c -rwxr-xr-x 1 vivek vivek 8544 Apr 28 09:14 dirp drwxrr2 vivek vivek 4096 Apr 28 09:15 viv vivek@vivek-VirtualBox $ ./dirp -d viv vivek@vivek-VirtualBox: $ ls -lrt I tail-5 - rwxr-xr-x 1 vivek vivek -rwxr-xr-x 1 vivek vivek 133 Apr 27 09:58 log_users.sh -rw-rr 1 vivek vivek 578 Apr 27 09:58 users.log rw-rr- 1 vivek vivek 505 Apr 28 09:13 dirp.c -rwxr-xr-x 1 vivek vivek 8544 Apr 28 09:14 dirp vivek@vivek-VirtualBox: $ 86 Apr 27 09:56 envir. sh 86 Apr 27 09:56 envir.sh

Add a comment
Know the answer?
Add Answer to:
Need Help doing this in C Please Help Search or enter website name Apple Disney ESPN...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • do numbers 4-8 4. Given any directory, use the Is command to display: • all files...

    do numbers 4-8 4. Given any directory, use the Is command to display: • all files and sub-directories starting with the letter "D" (note do not list anything in any sub-directory) • its immediate sub-directories (sub-directories only, and no other ordinary files) its immediate hidden sub-directories only - take a screenshot (#3-3) that clearly shows the command and the result. 5. Assume that the following files are in the working directory: $ ls intro notesb ref2 section 1 section3 section4b...

  • PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a...

    PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots ... and have it be in the same directory as the Python program you are coding for this assignment. IMPORTANT: Your program should work with any size file. It should work with 100 items listed or with no items in the file! Write a Python program that ... 1....

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT