Solved

how to delete file

Posted on 2000-05-16
9
278 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

790 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