0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

No.045【Python】作業ディレクトリの取得および変更

Posted at

python-logo-master-v3-TM-flattened.png

今回は、作業ディレクトリの取得・変更ついて書いていきます。

I'll write about acquiring and changing current directories

■ 作業ディレクトリの取得・確認

 To acquire and check current directories

 os.getcwd():作業ディレクトリの絶対パスを文字列として返す
>>> import os
>>> 
>>> path = os.getcwd()
>>> 
>>> print(path)
/Users/hauts5124/Documents
>>> 
>>> print(type(path))
<class 'str'>
>>> 
>>> # getcwd:get current working directoryの略

■ 作業ディレクトリを変更: os.chdir()

 Change current directories

os.chdir():作業ディレクトリを変更可能
引数に移動先パスを指定。絶対パス、相対パス双方可能
上の階層への移動は " ../ "
>>> os.chdir("../")
>>> 
>>> print(os.getcwd())
/Users/hauts5124
>>> 
>>> # chdir: chenge directoryの略

随時に更新していきますので、
定期的な購読をよろしくお願いします。
I'll update my article at all times.
So, please subscribe my articles from now on.

本記事について、
何か要望等ありましたら、気軽にメッセージをください!
If you have some requests, please leave some messages! by You-Tarin

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?