Solved

how to delete file

Posted on 2000-05-16
9
272 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
 

Author Comment

by:Madfun00
ID: 2815850
Thanks alot
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
The dreaded error 1935 with VC++ 2008 Redistributable 12 88
How to copy an image file into clipboard C/C++? 1 152
Header of docx file 17 97
VS2015 Redefinition errors 4 27
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now