8000 completed ospathutils · RobACurtis/Learning-Python@f79fc59 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit f79fc59

Browse files
committed
completed ospathutils
1 parent 2283ada commit f79fc59

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Ch3 - Files/ospathutils_start.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@
1212

1313
def main():
1414
# Print the name of the OS
15+
print(os.name)
1516

16-
1717
# 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"))
1821

19-
2022
# 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")))
2125

22-
2326
# Get the modification time
27+
t = time.ctime(path.getmtime("textfile.txt"))
28+
print(t)
29+
print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))
2430

25-
2631
# 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")
2935
if __name__ == "__main__":
3036
main()

0 commit comments

Comments
 (0)
0