在Python中移动目录结构的方法,python中移动目录,#Moving up/d
文章由Byrx.net分享于2019-03-23 10:03:26
在Python中移动目录结构的方法,python中移动目录,#Moving up/d
#Moving up/down dir structureprint os.listdir('.') # current levelprint os.listdir('..') # one level upprint 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 levelfor 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)
评论关闭