I am trying to perform a rather simple task.
A function accepts a TString as an argument and a boolan.
If the bool is true, then the file should be deleted.
This might seem strange but at some point later in the code a new root file is created. So I don’t know beforehand if I will use RECREATE of UPDATE as an option. So I decided to use UPDATE and if the bool is TRUE (i.e. the user doesn’t want to write again in this file) I delete the file using gSystem->Exec();
A simple version of the code can be found below
If you are running on Unix like system that will work. What Danilo suggested you is working on all systems for all kind of files. But assuming you are running on an Unix like system you can do something like:
The output of these few lines example proves it is working as expected:
root [0] .x delete_a_file.C
Processing delete_a_file.C...
ls: file_to_be_deleted: No such file or directory
file_to_be_deleted
ls: file_to_be_deleted: No such file or directory