• C

Copy, Delete, Rename, Show Unix Files using C

I am trying to write a simple file management prog using a simple menu, can anyone help me start. Thanks in advance.  
forestfireAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
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).

Like:

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!

Mayank.

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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KocilCommented:
And for the functions you need for deleting, renaming, copying etc, pleas look at :
http://www.cplusplus.com/ref/

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.


0
jmcgOwnerCommented:
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
Mayank SAssociate Director - Product EngineeringCommented:
Please proceed with that recommendation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.