- Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathP13_Python_Create_File_With_Metadata.py
More file actions
Latest commit
36 lines (33 loc) · 1.09 KB
/
Copy pathP13_Python_Create_File_With_Metadata.py
File metadata and controls
36 lines (33 loc) · 1.09 KB
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
#!/usr/bin/python3.6
importsys, os, datetime
defcreate_file(file_name):
'''
Create a flat file based on underlying Operating System
'''
ifsys.platform=='linux'orsys.platform=='darwin':
os.system('touch '+file_name)
elifsys.platform=='win32':
os.system('echo . > '+file_name)
defwrite_data_in_file(file_name):
'''
Write the metadata into the file
'''
ifsys.argv[3]:
iflen(sys.argv[3]) <=15:
length=15
else:
length=len(sys.argv[3])
else:
length=15
withopen(file_name, 'w') asfd:
fd.write('#'* (length+16))
fd.write('\n# Author: '+sys.argv[2])
fd.write('\n# Description: '+sys.argv[3])
fd.write('\n# Created at: '+datetime.datetime.today().strftime('%d %b %Y') +'\n')
fd.write('#'* (length+16))
if__name__=='__main__':
iflen(sys.argv) <=3:
print('You need to provide three arguments [File Name] [Author Name] [Description]')
exit()
create_file(sys.argv[1])
write_data_in_file(sys.argv[1])