🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ std remove

Started by
4 comments, last by MikeCyber 2 years, 5 months ago

Hi

struct stat attrib;

int nowdate = time(0);

stat(InFileLo.c_str(), &attrib);

int moddate = attrib.st_mtime;

if ((nowdate - moddate) >= 160000 ){

remove(InFileLo.c_str());

why does the above not remove the file? I have the same remove code line in other places in my project where it works. Debug runs through so it's maybe stat related?

Many thanks

Advertisement

As far as I know, Windows File Time is different than whatever time returns. You have to convert one into another to get the exact time you want

Time is not the problem as it enters the if condition. Thanks

Depending on the OS and/or filesystem, you may not be allowed to remove the file.

Did you check the result value of ‘remove’ ? It's generally good practice to do so if possible.

EDIT: https://en.cppreference.com/w/cpp/io/c/remove

Deletes the file identified by character string pointed to by fname.

If the file is currently open by the current or another process, the behavior of this function is implementation-defined (in particular, POSIX systems unlink the file name, although the file system space is not reclaimed even if this was the last hardlink to the file until the last running process closes the file, Windows does not allow the file to be deleted)

Emphasis is mine.

Yes, I forgot to close the file before remove. Solved thanks.

This topic is closed to new replies.

Advertisement