Skip to content

Commit

Permalink
Hopefully fixed recursive folder creation (Fixes #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiq0 authored and HexRx committed Jan 22, 2022
1 parent 0c1a8bb commit b1e78ba
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,32 @@ def checkSession(self):

# I think, there is easier way to do this...
# CDs to given directory, creating directories if needed
def cdRecursivelly(self, directory, prompt = True):
def cdRecursivelly(self, path, prompt = True, step = 1, splitPath = None):
self.checkSession()

if not splitPath:
splitPath = path.split('/')

directory = '/'.join(splitPath[:step])

try:
self.session.cwd(directory)
except ftplib.all_errors as e:
if str(e).split(None, 1)[0] != '550':
error('Could not set current working directory to "' + directory + '"\n' + str(e))
return False
if prompt:
if not ask('Directory "' + directory + '" does not exists, do you want to create it?', 'Yes'):
if not ask('Directory "' + path + '" does not exists, do you want to create it?', 'Yes'):
return False
# Ask only once for whole directory structure creation
prompt = False
self.session.mkd(directory)
self.session.cwd(directory)
self.cdRecursivelly('/'.join(directory.split('/')[:-1]), False)

return True
if step < len(splitPath):
return self.cdRecursivelly(path, prompt, step + 1, splitPath)
else:
return True

def connect(self):
start = time.time()
Expand Down

0 comments on commit b1e78ba

Please sign in to comment.