-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiletimereader.py
85 lines (73 loc) · 2.06 KB
/
filetimereader.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import subprocess
import sys
#output = subprocess.check_output("", shell=True)
#os.chdir() Changes directory
#os.getcwd() Gets current directory
#os.listdir() Lists all files/folders in directory
#[filename]
sys.setrecursionlimit(2000)
#List all files and folders
def listdir():
import os
files=os.listdir()
folderN=[]
fileN=[]
for File in files:
if os.path.isdir(File) and not os.path.islink(File):
folderN.append(File+"/")
else:
fileN.append(File)
return sorted(folderN)+sorted(fileN)
def filelister(startpath):
#Path variables
path=startpath
os.chdir(path)
path=os.getcwd()
if path[-1]!='/':
path+='/'
files=listdir()
allfiles=[]
#Go through every file in directory
for File in files:
if ("/proc" in File or "/snap" in File):
continue
k = 0
while (k < len(File)):
if (File[k] == "'"):
File = File[:k] + "\\" + File[k:]
k += 1
k += 1
if File[-1]=="/":
print("'"+path+File+"'")
allfiles=allfiles+filelister(path+File)
else:
allfiles.append("'"+path+"%s'"%(File))
return allfiles
def filetimewriter(files):
import os
os.chdir(startlocation)
# Variable for writing file dates in the csv file
with open("filedata.csv", "w") as dataWriter:
dataWriter.write("FileName"+":"+"Date changed"+":"+"Date Modified"+":"+"\n")
for File in files:
try:
output=subprocess.check_output("stat -c %z "+File, shell=True).decode().split()
output2 = subprocess.check_output("stat -c %y "+File, shell=True).decode().split()
#Make text to write in file, good format
writee=File+','+output[0]+' '+output[2]+','+output2[0]+' '+output2[2]+','+'\n'
print(writee)
if writee[:2]=="''":
writee=writee[2:]
nWritee=''
for char in writee:
nWritee+=char
if "''/" in nWritee:
nWritee=nWritee[:-3]
dataWriter.write(nWritee)
except:
pass
global startlocation
startlocation = os.getcwd()
allfiles = filelister("/")
filetimewriter(allfiles)