-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_modification_date.py
More file actions
26 lines (23 loc) · 944 Bytes
/
file_modification_date.py
File metadata and controls
26 lines (23 loc) · 944 Bytes
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
'''
The file_date function creates a new file in the current working directory,
checks the date that the file was modified, and returns just the date portion
of the timestamp in the format of yyyy-mm-dd. Fill in the gaps to create a
file called "newfile.txt" and check the date that it was modified.
'''
import os
import datetime
def file_date(filename):
# Create the file in the current directory
with open(filename,'w') as file:
pass
timestamp = os.path.getmtime(filename)
# Convert the timestamp into a readable format, then into a string
#print(timestamp)
readable_time = datetime.datetime.fromtimestamp(timestamp)
readable = datetime.datetime.date(readable_time)
#print(readable)
# Return just the date portion
# Hint: how many characters are in “yyyy-mm-dd”?
return ("{}".format(readable))
print(file_date("newfile.txt"))
# Should be today's date in the format of yyyy-mm-dd