-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosmodule.py
More file actions
48 lines (39 loc) · 1.16 KB
/
Copy pathosmodule.py
File metadata and controls
48 lines (39 loc) · 1.16 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
37
38
39
40
41
42
43
44
45
46
47
48
import os
from datetime import datetime
#PRINTING CURRENT DIRECTORY
print(os.getcwd())
#CHANGING DIRECTORY
os.chdir("/home/abhinav/Downloads")
print(os.getcwd())
#LISTING THE CONTENTS OF THE DIRECTORY
ls = os.listdir()
#MAKING A FOLDER
os.mkdir("game")
os.makedirs("mygame/thisismygame")
#DELETING A FOLDER
os.rmdir("game")
os.removedirs("mygame/thisismygame")
#RENAMING THE FILE
os.rename("test.py","odd.py")
os.rename("odd.py","test.py")
#STATS OF THE FILE
print(os.stat("test.py"))
modtime = os.stat("test.py").st_mtime
print(datetime.fromtimestamp(modtime))
#TRAVERSING THE DIRECTORY TREEE
for dirpaths,dirnames,filenames in os.walk(os.getcwd()):
pass
#print("dirpath : ",dirpaths)
#print("dirnames : ",dirnames)
#print(f"files : {filenames} \n\n")
#ENVIRONMENT VARIABLES
print(os.environ.get('USER'))
#JOINING PATHS
filepath = os.path.join("/home/abhinav",'test.txt')
basename = os.path.basename(filepath) #gives only test.txt
dirname = os.path.dirname(filepath)
both = os.path.split(filepath)
exists = os.path.exists(basename) #whether the file present or not
isdir = os.path.isdir(filepath)
serparatetype =os.path.splitext(filepath)
print(serparatetype)