Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to delete file

Posted on 2000-05-16
9
Medium Priority
?
298 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
[X]
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
  • 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 400 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
Independent Software Vendors: 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!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 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