You are here:

C++/Deleting Files


I am making my own program and would like some help. This program MUST delete files not related to it in any way in order for it to work. Please can you tell me the code for deleting files. Your help will be greatly appreciated.  

use "fuser" command using system() function in C++ (this would work for Unix machines) for the files that you are seeing. "fuser file_name" would return the program name which is using that file currently. But if the file is not being used currently (that is which may be used at the later point of time or was used earlier that the execution of this command would not be trapped hence this is not a complete solution).

Another way could be adding a logic in your code that would create a text file while starting up and would log all the files that it is reading/writing in that log file and you can delete all other files than those listed in that log file.

-- Dharmender Rai


All Answers

Answers by Expert:

Ask Experts


Dharmender Rai


I can answer general and system level C/C++ questions.


I have 5 years of experience in C++.

©2017 All rights reserved.