Thanks for sharing your solution.
- martin
import shutil
import xml.etree.ElementTree as ET
import os
syncdir = "k:\\sync" #these are some
updatedir = "k:\\" #directories
workingdir= "d:\\bue_update\\" #i'm working with
winscp_lsxml = "d:\\bue_update\\winscp\\winscp.com /script=ls_xml.winscp /xmllog=xmllog.xml" #this puts me a list of remote filenames into a xml
winscp_sync = "d:\\bue_update\\winscp\\winscp.com /script=sync_local.winscp" #this syncs so i can take the files
update_batch = updatedir+"\\ohnepause.bat"
os.system("connect_shares.bat")
os.system(winscp_lsxml)
os.system(winscp_sync)
newlog = ET.parse('xmllog.xml') #parses the fresh log from the os.system(winscp_lsxml) command
lastlog = ET.parse('last_xmllog.xml') #parses the log from the lasttime os.system(winscp_lsxml) command
root = newlog.getroot()
namespace = "{http://winscp.net/schema/session/1.0}"
filenames = root.findall('{0}ls/{0}files/{0}file/{0}filename'.format(namespace))
liste = []
for namen in filenames:
if "universal-lsb-rest-client" in namen.get('value'): #i dont't want this file
continue
elif ".zip" in namen.get('value'): #put all *.zip filenames in my list
liste.append(namen.get('value'))
for i in liste:
print(i)
print("Anzahl Elemente xmllog",liste.__len__())
last_root = lastlog.getroot()
last_filenames = last_root.findall('{0}ls/{0}files/{0}file/{0}filename'.format(namespace))
last_liste = []
for namen in last_filenames:
if ".zip" in namen.get('value'):
last_liste.append(namen.get('value')) #and make me a list of the lasttime log so i can compare
for i in last_liste:
print(i)
print("Anzahl Elemente last_xmllog",last_liste.__len__())
print("Vergleiche Listen...")
for namen in liste:
if namen not in last_liste: #here i compare the lists
print(namen)
cmd = workingdir + "7za.exe e " + syncdir + "\\" + namen+" -o"+updatedir+" -y" #and extract all files
print(cmd)
os.system(cmd)
shutil.copy("xmllog.xml","last_xmllog.xml") #save the fresh log for the next run
os.system(update_batch)
#os.system("disconnect_shares.bat")
FileTransferred
function to do what you need, it should be pretty easy:
for /f "delims=" %%a in ('dir /a-d /b /od *.zip') do set "newest=%%a"