Dec-14-2017, 11:35 AM
Hi all,
I'm rather new (obviously) to python, and I've been trying to work out how to get the below code to work properly / work out a different way of doing what I need.
Basically I'm getting a list of files from a remote server, all files will start with EXTRACT_INPUT_ followed by a date formatted like DDMMYYYY. I need to then make sure the file that I want to place does not have the same name so I'm just subtracting 1 day at a time until it does not exit and then that would be what I name my file.
import arrow def test(): datetoday = arrow.now().format('DDMMYYYY') filetoplace = "EXTRACT_INPUT_" + datetoday + ".TXT" remote_files = ['EXTRACT_INPUT_13122017.TXT', 'EXTRACT_INPUT_12122017.TXT', 'EXTRACT_INPUT_14122017.TXT'] while filetoplace in remote_files: filetoplace = "EXTRACT_INPUT_" + arrow.get(datetoday, 'DDMMYYYY').replace(days=-1).format('DDMMYYYY') + ".TXT" print(filetoplace) test()The code above does change the filetoplace variable to EXTRACT_INPUT_13122017.TXT, but it just keeps printing it over and over again.
My expected result is that the filetoplace variable ends up as EXTRACT_INPUT_11122017.TXT
Many thanks in advance!