Whoops, typo in that code. http://pastebin.com/5gtdjk3E
And just as an overview, this takes <name>, which I'm assuming is the current scene name, and splits that into basename, ext. Then it goes through each file in <path> and checks if the file follows the naming of <basename><separator><prefix><versionnumber><ext>, and if it does, stores that version number. On Monday, May 20, 2013 11:42:06 AM UTC-7, Jesse Capper wrote: > Firstly, os.listdir can't be guaranteed to return an alphanumerically sorted > file list. You're making the assumption that the latest processed file will > be the highest version number (when you use backups[-1]). I'd guess it uses > the way the files are index on your file system, so if you want to make sure > they are ordered a certain way, you should sort the return value. > > > > You can do your filename check and extract the version number using a single > regex: > > http://pastebin.com/ZF1XJs5S > > > > This use regex groups, which allow you to capture certain portions of a regex > (in this case the digits representing the version number), and access them > later. That way you can just store the version numbers and not have to parse > the filenames for the versions again. > > > > On Sunday, May 19, 2013 5:43:42 AM UTC-7, Ævar Guðmundsson wrote: > > > Ah well, hope this is correct but I appear to be able to do that check like > > this: > > > > > > #Name starts with scene name. > > > re.match( name , filename , flags=0 ) > > > > > > #Scene has same extension > > > os.path.splitext( filename )[1] == ext > > > > > > #Padding and prefix lengths match > > > re.search( r'%s%s%s\.' % ( seperator , '\w'*prefix , '\d'*padding ) , > > filename , flags=0 ) > > > > > > #Prefix name matches > > > name = filename.rfind('.') > > > Pa = 3 # length of padding > > > Pr = 1 # length of prefix > > > name[ name - ( Pa + Pr ) : name - Pa ] == prefix > > > > > > Feels a lot more 'lightweight' but please shout back with comments, I > > have no idea if I'm using python expressionism right or not :) -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
