I have some code that writes out files with names like this:
body00123.txt
body00124.txt
body00125.txt
body-1-2126.txt
body-1-2127.txt
body-1-2128.txt
body-3-3129.txt
body-3-3130.txt
body-3-3131.txt
Such that the first two numbers in the file can be 'negative', but the last 3 numbers are not.
I have a list such as this:
123
127
129
And I want to remove all the files that don't end with one of these numbers. An example of the desired leftover files would be like this:
body00123.txt
body-1-2127.txt
body-3-3129.txt
My code is running in python, so I have tried:
for i not in myList:
os.system('rm body*' + str(i) + '.txt')
And this resulted in every file being deleted.
body1123.txtorbody-2-123orbodyandsomethingelse00123.txtexist? And if yes, should it be deleted?body...files?for i not in myList:returns a syntax error in both python2 and python3. Is this the actual code you're running?