-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearCache.py
More file actions
49 lines (34 loc) · 1.36 KB
/
Copy pathClearCache.py
File metadata and controls
49 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#this removes obj and exe file generated by vcvarsall x64 // cl commands just to clean the repo while pushing into github
#general imports
import os
import sys
import re
#set path
#root_path = "C:\Users\User.FULL272-WIN.000\AppData\Local\Google\Chrome\User Data\Default\Cache"
root_path = "C:/Users/User.FULL272-WIN.000/Desktop/experiment"
#get total list of files available in directory
listofTotalFiles=os.listdir(root_path)
print("All the Available files in directory:\n "+ str(listofTotalFiles))
#filter only the files to be removed
#create regex
regex= "f_[\w]*"
for i in range(3,len(sys.argv)):
regex += ("|" + sys.argv[i])
print("regex=" + regex)
#get the removing files list
fileTypeRegex = re.compile(regex)
removingList = list(filter(fileTypeRegex.search, listofTotalFiles)) # Read Note
print("the following list of files will be removed =" + str(removingList) + "\n Continue ? Y/N")
# ask the user whether to delete the files shown
deleteFlag = input()
if deleteFlag.lower().__contains__('n'):
print("\nteriminating the process")
sys.exit(1)
#remove the files
for File in removingList:
try:
os.remove(os.path.join(root_path,str(File)))
print("file removed: " + str(File))
except OSError as e: ## if failed, report it back to the user ##
print ("Error: %s - %s." % (e.filename, e.strerror))
print("\n Deleted the files")