I have a working version of Python code, it reads files from each subfolder and save them into a list, however, there are quite a lot of files so the code takes a very long time to execute, is there a way to optimize the code below?
ftp_subdir_list = ['example_folder/2021/01/01', 'example_folder/2021/01/02', 'example_folder/2021/01/03',..................................., 'example_folder/2021/08/08', 'example_folder/2021/08/09']
ftp_file_list = []
for dir in ftp_subdir_list:
# login into FTP
ftp = ftplib.FTP_TLS(host)
ftp.login(username, password)
ftp.cwd(dir)
file_list = ftp.nlst()
ftp_file_list.append(file_list)
print(ftp_file_list)
Because there are quite a lot of folders and each folder has around 20 files, is there a way to optimize the code and increase the execution time? Is the for loop here slowing the speed? Thanks.