Copy, Delete, Rename, Show Unix Files using C

Posted on 2003-03-31
Medium Priority
Last Modified: 2010-04-15
I am trying to write a simple file management prog using a simple menu, can anyone help me start. Thanks in advance.  
Question by:forestfire
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 30

Accepted Solution

Mayank S earned 152 total points
ID: 8238012
Use a loop to display a menu as:

1. Copy
2. Delete
3. Rename
4. Show
5. Exit

and read the choice as an integer (or character). Based on this value, enter a switch statement block and perform the required operations in the corresponding case statement. Also provide for a default statement (invalid choice).


case 1: Read source filename, destination filename, and then copy (also check if the source-file exists, and whether a file by the destination filename is not already in existence - if so, then ask for another filename).

case 2: Read the filename and check if it is present. If yes, the delete it.

case 3: Read the filename and the new filename. Check if the file exists or not, and that a file by the new filename doesn't already exist. If allowed, then rename the file.

case 4: Read the filename. If the file is present, then read it (line by line, if its a text-file), and display it.

Now, if the choice was not 5 (exit), then loop again, else exit the program.

Hope that helps!


PS: Please don't ask for codes. Try to work out something and if you get any errors, then post it here so that we ca help you out.

Assisted Solution

Kocil earned 148 total points
ID: 8239272
And for the functions you need for deleting, renaming, copying etc, pleas look at :

Search for rename/remove.
There is no ready made copy function. You need to to open the original file for reading, and create the new_file for writing, then read/write manually. Use these functions: fopen, fread, fwrite, fclose, feof;

Show is practically the same as copy, just copy it to stdout instead to a new file.

LVL 20

Expert Comment

ID: 10199327
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between mayankeagle and Kocil.

Please leave any comments here within the next seven days.


EE Cleanup Volunteer
LVL 30

Expert Comment

by:Mayank S
ID: 10206761
Please proceed with that recommendation.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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