Deleting a File.

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";
}
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/
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 " ;
}
It's possible that Windows prevents the deletion of files.
Try deleting a file in the directory where you compile your program.
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++.
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.
I'm Having an Administrator account in windows.I have that much knowledge.lol
Topic archived. No new replies allowed.