-
Notifications
You must be signed in to change notification settings - Fork 44
/
Chapter_12th_os.py
42 lines (31 loc) · 1.11 KB
/
Chapter_12th_os.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
# Example 1
# Before executing this example, create tempdir folder in C:// directory
import os
os.chdir("C:\\tempdir")
# Example 2
os.getcwd() # get Current Working Directory
# output: 'C:\\tempdir'
# Example 3
os.chdir("C:\\tempdir")
os.getcwd()
# output: 'C:\\tempdir'
os.chdir("..")
os.getcwd()
# output: 'C:\\'
# Example 4
os.chdir("tempdir")
os.getcwd()
# output: 'C:\\tempdir'
os.rmdir("C:\\tempdir")
# Output
# PermissionError: [WinError 32] The process cannot access the file
# because it is being used by another process: 'C:\\tempdir'
# Example
# try any one from below in terminal.
os.listdir("C:\python37") # if you have this folder in C drive
# os.listdir("C:\Windows")
# Output of python37 folder:
# ['DLLs', 'Doc', 'fantasy-1.py', 'fantasy.db', 'fantasy.py', 'frame.py', 'gridexample.py',
# 'include', 'Lib', 'libs', 'LICENSE.txt', 'listbox.py', 'NEWS.txt', 'place.py', 'players.db',
# ,'tcl', 'test.py','© 'python3.dll', 'python36.dll', 'pythonw.exe', 'sclst.py', 'Script, 'python.exe',
# 'Tools', 'tooltip.py', 'vcruntime140.dll', 'virat.jpg', 'virat.py']