• Advertisement
Sign in to follow this  

stdio : remove does not delete files

This topic is 4406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

bool FileUtilities::Delete(const std::string& a_Filename)
{
	if (Exists(a_Filename) == true)
	{
		if (remove(a_Filename.c_str()) == -1)
			return false;
		else
			return true;
	}
	else
		return false;
}
For some reason the 'remove' command is not removing the file as soon as it completes. It indicates success but the file remains... until I exit the program. I had a look through the doco and can't find any referenced to any flush function that I need to perform. Any idea's on what is up?

Share this post


Link to post
Share on other sites
Advertisement
Hmm... did you open the file somewhere before you delete it? If you did, close it. If not... what the hell?

Share this post


Link to post
Share on other sites
No. The app I'm writing is a small utility to control archival of files. When the fil reaches a certain age it's archived and pruned from the OS. The issue is that when I delete the files out of a directory I check afterwards to see if the directory is now empty and remove it if it is. The empty directory check always fails as the files don't seem to disappear until the process exist. All 3-400 of them delete concurrently. I've also double checked this in a command prompt.

I've never seen anything like this before... and I'm sure I used to use that function to delete log files before creating a new one and it never caused me problems then...

Share this post


Link to post
Share on other sites
How do you check for file existence? And how do you check it's age? The files are being locked in some way...

Or maybe you are opening the directory file and locking it? If you are, the OS cannot update it (that is, remove the file from the directory).

Have you tried to open one of those deleted files after your program tries to remove them (before ending the process)? Don't you get a "file not found" error or something?

Share this post


Link to post
Share on other sites
Champion. You helped me find and error in my date checking code. It was not closing a handle. I didn't even realise it was using create file.

Share this post


Link to post
Share on other sites
Nice! Glad i could help. :)

EDIT:

This is a method i use when i can't find the source of some bug. Pretend you have a friend next to you (if you don't have any around) and explain him your problatic code, line by line. You'll find your problem in no time.

We programmers assume too much sometimes. Always re-check what you think you've coded correctly, no matter how simple it may be. Most bugs are just stupid things you didn't notice or remember.

Cheers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement