在Python中移動目錄結構的方法
更新時間:2016年01月31日 21:41:30 投稿:mdxy-dxy
這篇文章主要介紹了在Python中移動目錄結構的方法,需要的朋友可以參考下
來源:http://stackoverflow.com/questions/3806562/ways-to-move-up-and-down-the-dir-structure-in-python
#Moving up/down dir structure
print os.listdir('.') # current level
print os.listdir('..') # one level up
print os.listdir('../..') # two levels up
# more complex example:
# This will walk the file system beginning in the directory the script is run from. It
# deletes the empty directories at each level
for root, dirs, files in os.walk(os.getcwd()):
for name in dirs:
try:
os.rmdir(os.path.join(root, name))
except WindowsError:
print 'Skipping', os.path.join(root, name)
This will walk the file system beginning in the directory the script is run from. It deletes the empty directories at each level.
相關文章
python3 字符串/列表/元組(str/list/tuple)相互轉換方法及join()函數(shù)的使用
這篇文章主要介紹了python3 字符串/列表/元組(str/list/tuple)相互轉換方法及join()函數(shù)的使用 ,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04
python中的socket實現(xiàn)ftp客戶端和服務器收發(fā)文件及md5加密文件
這篇文章主要介紹了python中的socket實現(xiàn)ftp客戶端和服務器收發(fā)文件及md5加密文件的相關知識,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04

