I noticed that the local dicom database files stick around even when you delete all the patients, and will continue growing in size as more patients are added and removed. I would like to clean up these files to prevent any issues if a computer has to process many patients.
how would i do this in slicer? I know how to delete the files themselves, but they are in use during the runtime of the application as far as i can tell, and will throw an error of ‘File in use’
code i’m using:
import os, shutil
dir = os.path.dirname(slicer.dicomDatabase.databaseFilename)
shutil.rmtree(dir)
There could be multiple connection to the database from multiple modules. You probably need to restart Slicer to make sure none of them still uses the old database file.
so you are saying that the database couldn’t be cleared out in one session? is there any way to close down all the modules that might be using it, maybe when the application is closing, and just run the code for removing the files just before the app quits? or is there a place in slicer where data can be stored to persist until the next session where you could store the last database location and remove it when the next session runs?
that method should work for me. I just need to find how to set the local database folder through python, I’m not currently seeing the method to do that, could you point me in the right direction?
that is a way to access the current database, but it is not a writable variable.
Also, it points to the sql data file in the folder. If i just assigned that to a new path with the same data file name, would it create a new file with the given name or would i have to initialize the database somehow?