Browse Source

add `sortFiles.py`

Stephan Fuchs 5 months ago
parent
commit
7539d53f51
1 changed files with 23 additions and 0 deletions
  1. 23 0
      sortFiles.py

+ 23 - 0
sortFiles.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+import os.path
+import xml.etree.ElementTree as ET
+tree = ET.parse('glife.qproj')
+root = tree.getroot()
+
+
+rootFolder = 'sugarcube/src/autogenerated'
+unsortedFolder = os.path.join(rootFolder,'unsorted')
+
+for child in root[0]:
+    if(child.tag == 'Folder'):
+        folderName = child.attrib['name']
+        for subchild in child:
+            passageName = subchild.attrib['name']
+            oldFilePath = os.path.join(unsortedFolder,passageName+'.tw')
+            if(os.path.isfile(oldFilePath)):
+                newFolder = os.path.join(rootFolder,folderName)
+                os.makedirs(newFolder, exist_ok=True)
+                newFilePath = os.path.join(newFolder,passageName+'.tw')
+                os.replace(oldFilePath,newFilePath)
+