Python-os-chdir
提供:Dev Guides
Python os.chdir()メソッド
説明
Pythonのメソッド* chdir()*は、現在の作業ディレクトリを指定されたパスに変更します。すべての場合でNoneを返します。
構文
以下は* chdir()*メソッドの構文です-
os.chdir(path)
パラメーター
- path -これは、新しい場所に変更されるディレクトリの完全なパスです。
戻り値
このメソッドは値を返しません。
例
次の例は、chdir()メソッドの使用法を示しています。
#!/usr/bin/python
import os
path = "/usr/tmp"
# Check current working directory.
retval = os.getcwd()
print "Current working directory %s" % retval
# Now change the directory
os.chdir( path )
# Check current working directory.
retval = os.getcwd()
print "Directory changed successfully %s" % retval
上記のプログラムを実行すると、次の結果が生成されます-
Current working directory/usr
Directory changed successfully/usr/tmp