How could do delete any files within C++? Like you run an .exe and some files are deleted, like a game save or something.......example
c:\games\player1.txt
and then you want to delete that file.
Printable View
How could do delete any files within C++? Like you run an .exe and some files are deleted, like a game save or something.......example
c:\games\player1.txt
and then you want to delete that file.
system("del c:/games/player1.txt");
I'm sure there are better ways though.
Thank you.
Or use remove().
remove("c:\\games\\player1.txt");
Don't forget you need two backslahes to represent one backslash. Or you can use the forward slash, as Dual-Catfish shows.
Sorry to bring this up again, but instead of starting a whole new thread I decided to just bump it. How would I delete a whole directory? like ....c:\oldgamefiles\
You have to use a function called findnext or something like that. This will find the next file. From here, you can delete the file. Once you have deleted all files inside the directory, you can delete the directory.
system("rmdir mydirectory /s /q");
I thought it was:
// for Windows. deltree.exe is found in .../Windows/Command/...
system(deltree 'directory');
//use the following to get additional info on deltree.exe
system(deltree /?);
Thank you guys.
#include <iostream>
#include <conio.c> // Thats in Dev-C++4
#include <stdlib.h>
#include <stdio.h>
#include <string>
void main()
{
string directory="C:\\games\files\";
remove(directory);
cin.get();
}
Quote:
Originally posted by toaster
I thought it was:
// for Windows. deltree.exe is found in .../Windows/Command/...
system(deltree 'directory');
//use the following to get additional info on deltree.exe
system(deltree /?);
Would this delete the folder directory or just the files within the folder? How would I go about emptying the contents of a folder and leaving the folder. One more thing what website could I find this neat little "tricks"? because I dont' see any of these things in books.