Solved

how to delete file

Posted on 2000-05-16
9
275 Views
Last Modified: 2010-04-02
Here is what my problem is

I am reading stuff form a file, into the program. When it is done i want to delete the file from which i read in. But can't figure out a way of doing this. And need help :)
0
Comment
Question by:Madfun00
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2815710
If this program is always used in Windows you can use the DeleteFile method declared in winbase.h.

BOOL DeleteFile(
  LPCTSTR lpFileName   // pointer to name of file to delete
);
0
 

Author Comment

by:Madfun00
ID: 2815721
I am sorry, doing it in unix but thank u
0
 
LVL 1

Accepted Solution

by:
mournblade earned 100 total points
ID: 2815794
how about a system call?

e.g.:
char filename[] = "myFile.txt";
char system_call[256];
sprintf(system_call, "rm %s", filename);
system(system_call);
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:Madfun00
ID: 2815850
Thanks alot
0
 

Author Comment

by:Madfun00
ID: 2815985
i gave u the points right?? not sure if i did on didn't
0
 
LVL 22

Expert Comment

by:nietod
ID: 2816675
That works, but it is not a very efficient way to delete a file.  It requires that a new thread be started for the command processor and the command procssor has to be loaded and initialized in that thread, then the file is deleted, then the command processor terminated and the thread deleted.

You can just use the standard C procedure called remove().  Or you can use the UNIX system call called "unlink()" (I think that is the name.) to delete a file.
0
 
LVL 1

Expert Comment

by:mournblade
ID: 2817325
madfun00: yes you did.

nietod: i guess you're right. but if this is done only once, it doesn't really matter, does it? i thought that there were C fcns to do the job but i didn't know what they were. thanks for the info.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2818825
>> but if this is done only once, it doesn't
>> really matter, does it?
Not too much.  But its a very round-about and innefficient solution.  its like mailing a letter from NY to LA by getting on a plane and going from NY to LA then putting the letter in a mail box 1 block from its destination in LA.
0
 

Author Comment

by:Madfun00
ID: 2818895
Thank u mournblade, and nietod. It is interesting to see how much there is that i still need to know:). And thanks to both of u for the interesting solutions. I am already done and sumited my proj

regards
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

786 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