I got upset, you are right of course, I just do not understand the Python Loops...
Anyway, as I said, my task is to:
1. Scan remote machines (specific folders) for the ZIP files and Copy 1 (one) latest ZIP file but only if it has a file
Named "DEbug_xxx.log
2. Copy 1 (one) latest ZIP file that has "Debug_xxx.log" from each remote machine to a server.
The part of the script I need help with is the one I have already posted.
It accesses the remote machines and scans/makes a list of the ZIP files (newest to oldest)
Then it finds all the ZIPs with the file "debug_xxx.log" inside the ZIPs on each remote machine and
Copies all the ZIPS to different directories on my serve (actually on my server these directories named after the remote machine names), see below :
Not all as I do now.
I need to put a 'break' in the loop,
I tried to move the God damn 'break' all over the script and still cannot achieve my goal.
that is copying 1 (one) Zip file that has a 'Debug_xxx.log' inside the ZIP from each remote directory.
I hope it is clear but maybe not.
And again, I really appreciate your help!
Anyway, as I said, my task is to:
1. Scan remote machines (specific folders) for the ZIP files and Copy 1 (one) latest ZIP file but only if it has a file
Named "DEbug_xxx.log
2. Copy 1 (one) latest ZIP file that has "Debug_xxx.log" from each remote machine to a server.
The part of the script I need help with is the one I have already posted.
It accesses the remote machines and scans/makes a list of the ZIP files (newest to oldest)
lst_OF_files = os.listdir(d_to_sacn) ## Directory with ZIP files ## full_list = [os.path.join(d_to_sacn,i) for i in lst_OF_files] time_sorted_lst = sorted(full_list, key=os.path.getmtime) ## ZIP files Sorted started from Newest file ##
Then it finds all the ZIPs with the file "debug_xxx.log" inside the ZIPs on each remote machine and
Copies all the ZIPS to different directories on my serve (actually on my server these directories named after the remote machine names), see below :
try : for ls in time_sorted_lst : ls=ls.strip() #print ("______________ ",ls) with ZipFile (ls, 'r') as zip_file : file_name_list = zip_file.namelist () for file_name in file_name_list : if 'Debug_TIU' in file_name : ## Looking for a specific file Name ## print ("IN ZIP -->> ",ls) ls_p = ls.split('\\') dst = ndir_p+ls_p[-1] ## Creating a destination directory string ## print ("ZIP Name ---------->> ", ls_p[-1]) print ("Destination String -->> ",dst) shutil.copy(ls,dst) break except OSError as er : print ("ERROR Opening ZIP file ",file_name) continueBut I need to copy only a 1 (one) ZIp file from each remote machine,
Not all as I do now.
I need to put a 'break' in the loop,
I tried to move the God damn 'break' all over the script and still cannot achieve my goal.
that is copying 1 (one) Zip file that has a 'Debug_xxx.log' inside the ZIP from each remote directory.
I hope it is clear but maybe not.
And again, I really appreciate your help!