# Struggling With Removing a File? (C++)

## Recommended Posts

ajm113    355
I must be forgetting something, but the remove function with "std" doesn't work for me. I have it working like so:
		char Path[256];
sprintf(Path, "GameFolders\\%s\\%s\\%s", str.Email, str.GameName, str.fileName);

remove((const char*)Path);


I'm using this function on Windows platform. Do I need a "full length" path to that file for it to delete? I want to recreate a file in it's place, but I have to remove it first before I recreate it. :S Thank you, sorry this question seems to be kinda low level for me, but I guest we all can't know or remember everything.

##### Share on other sites
demonkoryu    980
What's the error?

##### Share on other sites
cache_hit    614
I believe the problem to be that std::remove has nothing to do with files. ;-)

If you're on Windows, use ::DeleteFile(path). If you're using boost, you can use boost::filesystem::remove(). but std::remove is for a completely different purpose.

##### Share on other sites
demonkoryu    980
Quote:
 Original post by cache_hitI believe the problem to be that std::remove has nothing to do with files. ;-)

That's what I also thought at first, but...

##### Share on other sites
ajm113    355
I mean this remove function not the std then. hehe, I tried that as well and it returns false all the time. I'm guesting it's a value issue? Here is Path's
value = "GameFolders\Accounts\myEmail@yahoo.com\SomeGame\myGame.txt".

##### Share on other sites
demonkoryu    980
Quote:
 Original post by ajm113it returns false

Precisely, it returns an integer. So it returns 0. That means success.

##### Share on other sites
ajm113    355
[EDIT]
Oh I didn't close a handle that was created before that. >,< Alright well it works now! Thank you guys!

[Edited by - ajm113 on March 10, 2010 12:13:33 AM]