Deleting a File.

Jul 20, 2011 at 7:00am
I tried to delete a file in the system using function remove()(fstream.h).
and that file is presend in some other location in the computer.
So I tried using chdir to change directory But it isn't working.
This is the foll program.Help me out please.
#include<dir.h>
#include<stdio.h>
#include<fstream.h>
void main()
{
chdir("D:\\");
remove("BOON.DAT");
if(!"BOON.DAT")
cout<<"File removal sucessful";
else
cout<<"Unable to remove file";
}
Jul 20, 2011 at 8:31am
First, please use [code] [/code] tags around your source codes.
Second, remove() is part of stdio.h not fstream.h.
Third, that's not how you check if your program deleted the files.
Fourth, you could probably simply use remove("D:\\BOON.DAT"); without chdir().

Example here:
http://www.cplusplus.com/reference/clibrary/cstdio/remove/
Jul 20, 2011 at 8:48am
I tried but didn't work.
1
2
3
4
5
6
7
8
9
#include<stdio.h>
#include<fstream.h>
void main()
{
	if(remove("D:\\BOON.DAT")==0)
		cout<<"File removal Sucessful ";
	else
		cout<<"Unable to delete file " ;
}
Jul 20, 2011 at 8:59am
It's possible that Windows prevents the deletion of files.
Try deleting a file in the directory where you compile your program.
Jul 20, 2011 at 9:01am
yeah,It works there.I'm trying to delete files out of my directory,Thats why I tried using chdir,but It didn't work either.I use turbo C++.
Jul 20, 2011 at 9:06am
If you're using a limited user account in Windows and not the Administrator account, forget about deleting files you do not control such as system files. Your programs do not have more rights than you do.
Jul 20, 2011 at 9:15am
I'm Having an Administrator account in windows.I have that much knowledge.lol
Jul 21, 2011 at 10:47am
Topic archived. No new replies allowed.