diff --git a/insert_wordpress.py b/insert_wordpress.py index c91964b..db2e8a0 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -15,9 +15,8 @@ class WPimport: def fromDirectory(self, directory): directory = "{0}/archives".format(directory) - for item in os.listdir(directory): - subdirectory = self._checkDirectory(item) - print(subdirectory) + subdirectory = self._checkDirectory([], "{0}".format(directory)) + print(subdirectory) def fromFile(self, files): @@ -34,10 +33,13 @@ class WPimport: # Private method - def _checkDirectory(self, item): - if os.path.isdir(item): - self._checkDirectory(item) - return item + def _checkDirectory(self, subdirectory, item): + sub = subdirectory + for i in os.listdir(item): + if os.path.isdir("{0}/{1}".format(item, i)): + sub.append("{0}/{1}".format(item, i)) + subdirectory = self._checkDirectory(sub, "{0}/{1}".format(item, i)) + return subdirectory ## Add or update featured media