-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentDirectoryChange.py
More file actions
124 lines (94 loc) · 3.59 KB
/
CurrentDirectoryChange.py
File metadata and controls
124 lines (94 loc) · 3.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Win-10
#
# Created: 16/06/2019
# Copyright: (c) Win-10 2019
# Licence: <your licence>
#-------------------------------------------------------------------------------
#https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory
#https://stackoverflow.com/questions/3718657/how-to-properly-determine-current-script-directory
#https://stackoverflow.com/questions/431684/how-do-i-change-directory-cd-in-python
#https://stackoverflow.com/questions/8248397/how-to-know-change-current-directory-in-python-shell
#https://stackoverflow.com/questions/431684/how-do-i-change-directory-cd-in-python
#https://stackoverflow.com/questions/tagged/working-directory
print("""
#https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory
#https://stackoverflow.com/questions/3718657/how-to-properly-determine-current-script-directory
#https://stackoverflow.com/questions/431684/how-do-i-change-directory-cd-in-python
#https://stackoverflow.com/questions/8248397/how-to-know-change-current-directory-in-python-shell
#https://stackoverflow.com/questions/431684/how-do-i-change-directory-cd-in-python
#https://stackoverflow.com/questions/tagged/working-directory
""")
print("""To get the current working directory use
import os
print(os.getcwd())
""")
import os
print(os.getcwd())
print("# Prints the current working directory")
# Prints the current working directory
print("#To set the working directory:")
#To set the working directory:
print(os.chdir('G:/PyWorkDirectory'))
print("""
To # Provide the new path here
os.chdir('Python folder name or The desider directory name ')
""")
# Provide the new path here
file3 = open("G:/PyWorkDirectory/640px-Computer_system_bus.svg", "rb")
print(file3.read())
file3.close()
print(""" import os
cwd = os.getcwd()
print(cwd)
""")
import os
cwd = os.getcwd()
print(cwd)
#current answer is C:\Users\Win-10\AppData\Local\Temp
print("To get the current working directory use")
print("""
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
""")
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
print("""
(Note that the incantation above won't work if you've already used os.chdir()
to change your current working directory, since the value of the __file__
constant is relative to the current working directory and is not changed by
an os.chdir() call.)
""")
print("""
You may find this useful as a reference:
import os
print("Path at terminal when executing this file")
print(os.getcwd() + "\n")
print("This file path, relative to os.getcwd()")
print(__file__ + "\n")
print("This file full path (following symlinks)")
full_path = os.path.realpath(__file__)
print(full_path + "\n")
print("This file directory and name")
path, filename = os.path.split(full_path)
print(path + ' --> ' + filename + "\n")
print("This file directory only")
print(os.path.dirname(full_path))
""")
#You may find this useful as a reference:
import os
print("Path at terminal when executing this file")
print(os.getcwd() + "\n")
print("This file path, relative to os.getcwd()")
print(__file__ + "\n")
print("This file full path (following symlinks)")
full_path = os.path.realpath(__file__)
print(full_path + "\n")
print("This file directory and name")
path, filename = os.path.split(full_path)
print(path + ' --> ' + filename + "\n")
print("This file directory only")
print(os.path.dirname(full_path))