-
Notifications
You must be signed in to change notification settings - Fork 0
/
osStuff.py
66 lines (46 loc) · 1.41 KB
/
osStuff.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
from datetime import datetime
# Makes directory but can't make parents if they don't exist
# os.mkdir('newDir')
# Remove directory but can't make parents if they don't exist
#os.rmdir('newDir')
#Makes Sub directories and parents if they don't exist
#os.makedirs('newDir2/Sub-Dir-1')
#os.removedirs('newDir2/Sub-Dir-1')
print(os.stat('demo.txt'))
# Store timestamp of file
mod_time = os.stat('demo.txt').st_mtime
print(datetime.fromtimestamp(mod_time))
# Rename File
#os.rename('test.txt', 'demo.txt')
"""
# List Working Directory
print(os.listdir())
print(os.getcwd())
"""
"""
# Change working directory
os.chdir('/home/jpon/PycharmProjects/')
print(os.getcwd())
"""
"""
# Walk through each directory and print out directory & filenames
for dirpath, dirnames, filenames in os.walk('/home/jpon/PycharmProjects/'):
print('Current Path:', dirpath)
print('Directories:', dirnames)
print('Files:', filenames)
print()
"""
print(os.environ.get('HOME'))
"""
# Manual way to specify path, but can be prone to errors if one forgets the "/". Use join instead
file_path = os.environ.get('HOME') + 'test.txt'
print(file_path)
"""
# Join file path using os function
file_path = os.path.join(os.environ.get('HOME'), 'test.txt')
print(file_path)
# Print directory vs filename
print(os.path.split('/tmp/tmp2/test.txt'))
# Print directory and filename vs extension
print(os.path.splitext('/tmp/tmp2/test.txt'))