-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_basic_01.py
More file actions
51 lines (43 loc) · 959 Bytes
/
os_basic_01.py
File metadata and controls
51 lines (43 loc) · 959 Bytes
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
'''
@Author : Md. Shamimul Islam
@Written : 02/03/2019
@Description: python Operating System Basic
'''
import os
"""
getcwd()
The getcwd() method returns the current working directory in the form of a string
"""
#print(os.getcwd())
"""
chdir()
chdir() is the Python equivalent of cd. Call the method and pass it the directory that you want to change to as a string.
"""
os.chdir('/home/shamim/Documents')
#print(os.getcwd())
#go back perents dir
os.chdir('../')
#go back Documents folder
os.chdir('/home/shamim/Documents/Python')
print(os.getcwd())
"""
make directory
"""
os.mkdir('new_folder')
documents_list=os.listdir('/home/shamim/Documents/Python')
print(documents_list)
""""
make directories
"""
os.makedirs('1/2/3/4/5')
documents_list=os.listdir('/home/shamim/Documents/Python')
print(documents_list)
"""
remove operation
"""
#remove a file
os.remove('t.py')
#remove a directory
os.rmdir('1')
"""Rename"""
os.rename('ty.py'.'ty_1.py')