Hi I have some code which works nine times out of ten. Maybe some could help me make this a little more robust. I have a bunch of files in a folder with a strict versioning based naming convention, where I want to open the highest version number of a nuke script (not necessarily the one with the newest modification date). So in the example folder contents listed below I want to open "233_bb0072_comp_comp2k_v05.nk" (fourth from the bottom). Every once in a while my python script ends up opening 233_bb0072_comp_comp2k_v04.nk (the next to last correct one). The script I am using is shown below. Can anyone explain why it doesn't always work?<br>
<br><br>233_bb0072_comp_comp2k_v01.nk<br>233_bb0072_comp_comp2k_v01.nk~<br>233_bb0072_comp_comp2k_v02.nk<br>233_bb0072_comp_comp2k_v03.nk<br>233_bb0072_comp_comp2k_v03.nk~<br>233_bb0072_comp_comp2k_v04.nk<br>233_bb0072_comp_comp2k_v04.nk~<br>
233_bb0072_comp_comp2k_v05.nk<br>233_bb0072_comp_comp2k_v05.autosave<br>233_bb0072_comp_comp2k_v05.nk~<br>233_bb0072_comp_comp2k_v06.nk<br><br>#######################################<br>import os<br>def openNewestCompCommandLine():<br>
<br> theDirectory = "/path/to/my/comps/"<br> theFilesInTheFolder = os.listdir(theDirectory)<br> for aFile in theFilesInTheFolder:<br> if "~" not in aFile:<br> if "autosave" not in aFile:<br>
theNukeFileName = aFile<br> <br> theFullPath = theDirectory + theNukeFileName<br> os.system("nuke " + theFullPath)<br>if __name__ == '__main__':<br> openNewestCompCommandLine()<br>
<br>for aFile in theFilesInTheFolder:<br> print aFile<br>################################################<br>Pete<br><br><br>