File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 12
12
13
13
def main ():
14
14
# Print the name of the OS
15
+ print (os .name )
15
16
16
-
17
17
# Check for item existence and type
18
+ print ("Item exists:" , str (path .exists ("textfile.txt" )))
19
+ print ("Item is a file:" , path .isfile ("textfile.txt" ))
20
+ print ("Item is a directory:" , path .isdir ("textfile.txt" ))
18
21
19
-
20
22
# Work with file paths
23
+ print ("Item's path:" , path .realpath ("textfile.txt" ))
24
+ print ("Item's path and name:" , path .split (path .realpath ("textfile.txt" )))
21
25
22
-
23
26
# Get the modification time
27
+ t = time .ctime (path .getmtime ("textfile.txt" ))
28
+ print (t )
29
+ print (datetime .datetime .fromtimestamp (path .getmtime ("textfile.txt" )))
24
30
25
-
26
31
# Calculate how long ago the item was modified
27
-
28
-
32
+ td = datetime .datetime .now () - datetime .datetime .fromtimestamp (path .getmtime ("textfile.txt" ))
33
+ print ("It has been" , td , "since the file was modified" )
34
+ print ("Or," , td .total_seconds (), "seconds" )
29
35
if __name__ == "__main__" :
30
36
main ()
You can’t perform that action at this time.
0 commit comments