I have code that intends to iterate through a directory hierarchy, and, for every file at the bottom of the hierarchy, create a file.
for currentDirectory, listOfSubDirectories, listOfStructures in os.walk(projectsLocation):
#this says if we arent at the bottom of the directory chain, do nothing (checks if subDirectoryList is 0)
if not listOfSubDirectories:
##THIS IS WHERE WE DO THINGS FOR ONE SIMULATION##
for currentStructure in listOfStructures:
if "Abridged" in currentStructure:
os.remove(currentStructure)
abridgedVersion=open(currentStructure[:-4]+"Abridged","w+")
Extremely bizarrely, however, is that the code places 2 of the files files at the top of the directory!
Even stranger is that when i rerun the code with error-checking print statements, printing the three lists, the files that get printed at the top of the directory "cant be found" despite the fact that they arent even in the list of files!
i.e.
/home/parker/pretendFoldingData/proj8202/run2/clone1
[]
['structure1.pdb', 'structure0Abridged', 'structure0.pdb']
Traceback (most recent call last):
File "importAtomFileMaker.py", line 35, in <module>
os.remove(currentStructure)
FileNotFoundError: [Errno 2] No such file or directory: 'structure1Abridged'
I hope this was even slightly clear..... can someone please advise?