本文从增删改查角度,演示几种常用的 Python 目录操作
In [10]: ls
ambari_customization/ mylovelycodes/ tensorflow-cuda.whl* video/
bak_ambari-web/ tensorflow-cuda-mkl.whl* tensorflow.whl*
In [11]: os.mkdir("test")
In [12]: ls
ambari_customization/ mylovelycodes/ tensorflow-cuda.whl* test/
bak_ambari-web/ tensorflow-cuda-mkl.whl* tensorflow.whl* video/
In [20]: os.listdir("./")
Out[20]:
['test',
'ambari_customization',
'bak_ambari-web',
'tensorflow-cuda-mkl.whl',
'tensorflow.whl',
'tensorflow-cuda.whl',
'mylovelycodes',
'video']
In [21]: os.rename("test","newname")
In [22]: os.listdir("./")
Out[22]:
['ambari_customization',
'bak_ambari-web',
'newname',
'tensorflow-cuda-mkl.whl',
'tensorflow.whl',
'tensorflow-cuda.whl',
'mylovelycodes',
'video']
In [23]: os.rmdir("newname")
In [24]: os.listdir("./")
Out[24]:
['ambari_customization',
'bak_ambari-web',
'tensorflow-cuda-mkl.whl',
'tensorflow.whl',
'tensorflow-cuda.whl',
'mylovelycodes',
'video']