Hi Thoma. My advice would be as a starting point don't use the re module if
you don't have to. You can isolate the version in a much more readable way
using standard python string and list methods. The code below reads as
follows.
"For a given file path, split it on its separator and for each item you get
in that list find the item that returns True for the following two
conditions: 1) that it begins with 'v' and 2) that everything after the 'v'
within that one that you found is a number.
##################################################
theFilePath = "x:/projects/sequences/shot_01/v003/"
theFilePathAsList = theFilePath.split("/")
for anItem in theFilePathAsList:
if anItem.startswith("v"):
if anItem[1:].isdigit():
print anItem
#################################################
Hope that helps
Pete
*Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems. *
<http://www.jwz.org/>Jamie Zawinski
On Thu, Aug 30, 2012 at 9:38 AM, thoma
<[email protected]>wrote:
> **
> Hi everyone,
>
> I'm trying to search a file path list (split by'/') for the version
> directory and return the index number of that object in that list. So if my
> path is:
>
> x:\projects\sequences\shot_01\v003\
>
> i want to search with something like
>
> match = re.search( r'(v|V|_v|_V)\d+', myPath)
>
> then get the index number of the result.
> Right now i'm using match.object() to get the matched value as a string
> but does this result contain the index value as well?
>
> Full disclosure - I'm trying to piece together a set version to latest
> script that accounts for paths with version folders and version string in
> the file name because all the scripts i've found have certain assumptions
> about the folder structure hard-coded into the script. I've tried the one
> here:
> http://www.nukepedia.com/python/nodegraph/version-to-latest/
> ...which looks like exactly what i want but I always get a
> "'AttributeError: 'NoneType' object has no attribute 'group'"
>
> Also, the built in version.py (apparently used by DD 'and Weta,
> apparently')
> doesn't seem to do anything at all.
>
> Any help is much appreciated!
>
> Thomas
>
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
--
-
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python