sortFiles.py 778 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python3
  2. import os.path
  3. import xml.etree.ElementTree as ET
  4. tree = ET.parse('glife.qproj')
  5. root = tree.getroot()
  6. rootFolder = 'sugarcube/src/autogenerated'
  7. unsortedFolder = os.path.join(rootFolder,'unsorted')
  8. for child in root[0]:
  9. if(child.tag == 'Folder'):
  10. folderName = child.attrib['name']
  11. for subchild in child:
  12. passageName = subchild.attrib['name']
  13. oldFilePath = os.path.join(unsortedFolder,passageName+'.tw')
  14. if(os.path.isfile(oldFilePath)):
  15. newFolder = os.path.join(rootFolder,folderName)
  16. os.makedirs(newFolder, exist_ok=True)
  17. newFilePath = os.path.join(newFolder,passageName+'.tw')
  18. os.replace(oldFilePath,newFilePath)