def clone_dir(src, dest):
 for x in os.listdir(src):
  dpath = os.path.join(dest, x)
  spath = os.path.join(src, x)
  if os.path.isdir(spath):
   os.mkdir(dpath)
   clone_dir(spath, dpath)
  else:
   try:
    hardlink_file(spath, dpath)
   except:
    shutil.copy2(spath, dpath)

def clone_dir ( src , dest ) : for x in os . listdir ( src ) : dpath = os . path . join ( dest , x ) spath = os . path . join ( src , x ) if os . path . isdir ( spath ) : os . mkdir ( dpath ) clone_dir ( spath , dpath ) else : try : hardlink_file ( spath , dpath ) except : shutil . copy2 ( spath , dpath )
simulates creation of a directory called clone_dir inside of tmpdir .