SoFunction
Updated on 2024-11-19

Moving Directory Structures in Python

source (of information etc):/questions/3806562/ways-to-move-up-and-down-the-dir-structure-in-python

#Moving up/down dir structure
print ('.') # current level
print ('..') # one level up
print ('../..') # 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 (()):
  for name in dirs:
    try:
      ((root, name))
    except WindowsError:
      print 'Skipping', (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.