albie0803
Alibre Super User
I think it would be better to only delete files that your script creates. For all we know Alibre Design could be creating files in that folder that it needs.
You could create your own subfolder. Take a look at tempfile.mkdtemp().
Andy
I have wrestled with the code (and google) and come up with the following that checks if a temp directory exists, if not, creates it and if so deletes the contents of it.
Code:
import tempfile
import os
# define temp folder
tmp = tempfile.gettempdir() + '\\alibre\\'
# if no temp folder create it
if os.path.isdir(tmp) == False:
os.makedirs(tmp)
else:
#delete file in temp folder
for the_file in os.listdir(tmp):
file_path = os.path.join(tmp, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(e)
This will go at the beginning of the script.