MCPcopy Create free account
hub / github.com/LinkedInLearning/learning-python-2896241 / main

Function main

Ch3 - Files/ospathutils_finished.py:13–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import time
12
13def main():
14 # Print the name of the OS
15 print (os.name)
16
17 # Check for item existence and type
18 print ("Item exists: " + str(path.exists("textfile.txt")))
19 print ("Item is a file: " + str(path.isfile("textfile.txt")))
20 print ("Item is a directory: " + str(path.isdir("textfile.txt")))
21
22 # Work with file paths
23 print ("Item's path: " + str(path.realpath("textfile.txt")))
24 print ("Item's path and name: " + str(path.split(path.realpath("textfile.txt"))))
25
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")))
30
31 # Calculate how long ago the item was modified
32 td= datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
33 print ("It has been " + str(td) + " since the file was modified")
34 print ("Or, " + str(td.total_seconds()) + " seconds")
35
36if __name__ == "__main__":
37 main()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected