Jan-07-2022, 02:16 PM
(Jan-06-2022, 09:08 PM)snippsat Wrote:(Jan-06-2022, 05:23 PM)cubangt Wrote: But i guess where im running into questions is, would it be possible to save/download each file into its appropriate folder while getting them from the FTP server? Or do i have to download them all first and then move them into the appropriate folders?I guess this could be configure from FTP.
Can show demo if have downloads file,uisng pathlib(a more modern way to work with filesystem/paths) and shutil.
from pathlib import Path import shutil src_path = r'C:\code\weather' d_list = ['booking', 'shipment', 'po', 'monthly'] for file, name in zip(Path(src_path).glob('*.txt'), d_list): #print(file, name) # Test new_path = f'{src_path}/{name}' Path(new_path).mkdir(parents=True, exist_ok=True) shutil.copy(file, new_path) # .move as name say will move filesSo in src_path i have 1.txt, 2.txt ... this files will be copy to src_path/booking/1.txt, src_path/shipment/2.txt ...
thanks for the suggestion/example, ill have time today to try and implement this into my code and test it out.