Skip to content

Commit 25862c3

Browse files
committed
Added os module related methods
1 parent e3805b3 commit 25862c3

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

  • Sep21/EffectivePython/StandardLibrary/osandrelatedmodules
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
3+
4+
5+
def current_cwd():
6+
cwd = os.getcwd()
7+
print(f"the current working directory is {cwd}")
8+
9+
if __name__ == "__main__":
10+
current_cwd()
11+
os.chdir("../")
12+
current_cwd()
13+
folder_path = os.path.join(os.getcwd(),'osandrelatedmodules')
14+
os.chdir(folder_path)
15+
current_cwd()
16+
parent_directory = os.getcwd()
17+
data_dir = os.path.join(parent_directory,"data")
18+
if not os.path.exists(data_dir):
19+
os.mkdir(data_dir)
20+
21+
22+
# recursive folder creation
23+
csv_dir = os.path.join(data_dir,"files", "csv")
24+
if not os.path.exists(csv_dir):
25+
os.makedirs(csv_dir)
26+
27+
parent_directory = "D:\\khajaclassroom\\python_intensive"
28+
dir_list = os.listdir(parent_directory)
29+
print(dir_list)
30+
31+
parent_directory="D:\\temp\\test"
32+
for root, d_names, f_names in os.walk(parent_directory):
33+
print(root,d_names,f_names)
34+
35+
# Commonly used functions
36+
print(os.name)
37+
38+
#os.rename(src="test.txt", dst="newtest.txt")
39+
40+
#os.path.getsize()
41+
42+
43+
44+

0 commit comments

Comments
 (0)