I have a Python script and I\'m trying to delete all files in this directory EXCEPT for the .csv file. Getting syntax error on the \"not\" in this line:
for
An alternate way would be get the list of files (glob.glob returns a list) and then remove the one item you want to preserve.
import os
import glob
import time
file_path = "c:\python\AIO.csv"
while not os.path.exists(file_path):
time.sleep(10)
if os.path.isfile(file_path):
# get list of files that match
cleanupFiles = glob.glob("c:\python\AIO*.*")
cleanupFiles.remove(file_path)
for cleanupFile in cleanupFiles:
os.remove(cleanupFile)