-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOS_Module.py
More file actions
51 lines (38 loc) · 1.53 KB
/
OS_Module.py
File metadata and controls
51 lines (38 loc) · 1.53 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
49
50
import os
#Checking method avialable for OS Module
print(dir(os))
#Check the Current Working Directory
print(os.getcwd())
#Rename a File
os.rename('news.txt','new-new.txt')
os.rename('new-new.txt','news.txt')
#Change the current working Directory
os.chdir("c:/")
print(os.getcwd())
#list inside a directory
print(os.listdir())
#MakeDirectory and Remove Diectory
#Create Single Directory
os.mkdir('Python-Test-Directory')
#Remove Single Directory
os.rmdir('Python-Test-Directory')
#Make Recursive Directory
os.makedirs('Python-Test-Directory-001/Python-Test-SubDirectory-001/Python-Test-2SubDirectory-001')
#Delete Recursive Directory
os.removedirs('Python-Test-Directory-001/Python-Test-SubDirectory-001/Python-Test-2SubDirectory-001')
'''
#Traveresing through Directory
print("------------------------------------------")
print("Walking through directory")
print("------------------------------------------")
for dirpath,dirname,filenames in os.walk('c:/Users/Savit/Ruby'):
print("CurrentPath :{}".format(dirpath))
print('Directory Name: {}'.format(dirname))
print("File-Name: {}".format(filenames))
print("------------------------------------------")
'''
#Python OS.path
print(os.path.exists("No_suct_file.txt"))#Returns Bolean True or False =>False
print((os.path.basename("C:\\Users\\Savit\\python\\Os_Module.py"))) #Reten the File name OS_Modile.txt
print(os.path.splitext("Os_Module.py")) #Reurn the file Name and the extention ('Os_Module', '.py')
print(os.path.join("C:\\Users\\Savit\\python","Os_Module.py"))#joins the File Name with Path