LoginSignup
2
7

More than 3 years have passed since last update.

カレントディレクトリに対するコマンド Python

Last updated at Posted at 2020-04-26

カレントディレクトリに対するコマンド

全てosモジュールを使用するので

import os

を最初に打っておく。

  • カレントディレクトリのパス名を取得

    path = os.getcwd()
    print(path)
    
  • カレントディレクトリ内のフォルダやファイルの表示

    ls = os.listdir(os.getcwd())
    print(ls)
    
  • ディレクトリの移動

    os.chdir("Desctop")    #移動はこれだけでOK
    curdir = os.getcwd()
    print(curdir)
    
  • カレントディレクトリのディレクトリ名を取得

    curdirname = os.path.basename(os.getcwd())
    print(curdirname)
    
2
7
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
2
7