So I found a way to do it, maybe some people could be interested:<br><br>listNames = []<br>for n in names:<br> listNames.append('_'.join(n.split('_')[:-1]))<br>#It will cut the last part of the file name convention <br>
<br>listNames = list(set(listNames)) #we Delete duplicates from the list, like this we only have what we are interested in <br>for e in listNames: #Juste to check.<br> print e<br><br>:)<br><br><br><br><div class="gmail_quote">
2010/8/26 Alban Nona <span dir="ltr"><<a href="mailto:python.koda@gmail.com">python.koda@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hey ! Thank you guys !<br>It help me a lot !<br><br>@Dennis (Gomes): Thanks ! I tried it it worked well but list me the whole files :P (and finally crashed python...lol)<br><br>I looked at the Peter method and, Im really dumb to didnt tough about defining a pattern like *_v001.0001.exr * like this, it sort me only one frame...which is perfect and less memory consuming I guess.<br>
<br>And glob use seems to be perfect for what I want to do ! so thank you to point me in this direction :p<br><br>I tried also the Peter code, and it give me a good listing of my element like I wanted:<br><br>HPO7_SEQ004_031_VDMRoom_ALB<br>
HPO7_SEQ004_031_VDMRoom_AMB<br>HPO7_SEQ004_031_VDMRoom_BTY<br>HPO7_SEQ004_031_VDMRoom_Cutouts_ALB<br>HPO7_SEQ004_031_VDMRoom_Cutouts_AMB<br>HPO7_SEQ004_031_VDMRoom_Cutouts_DET<br>....<br>HPO7_SEQ004_031_VDMRoom_DET<br>HPO7_SEQ004_031_VDMRoom_DIF<br>
HPO7_SEQ004_031_VDMRoom_DPF<br>HPO7_SEQ004_031_VDMRoom_Decals_ALB<br>....<br>HPO7_SEQ004_031_VDM_ALB<div class="im"><br>HPO7_SEQ004_031_VDM_AMB<br></div>HPO7_SEQ004_031_VDM_BTY<div class="im"><br>HPO7_SEQ004_031_VDM_DIF<br>
</div>HPO7_SEQ004_031_VDM_DPF<br>HPO7_SEQ004_031_VDM_Fresnel_mat<br>
<br><br>Unfortunatly, a new problem come to me, I looking to get that kind of list:<br><br>HPO7_SEQ004_031_VDMRoom<br>HPO7_SEQ004_031_VDMRoom<br>HPO7_SEQ004_031_VDMRoom<br>HPO7_SEQ004_031_VDMRoom_Cutouts<br>HPO7_SEQ004_031_VDMRoom_Cutouts<br>
HPO7_SEQ004_031_VDMRoom_Cutouts<br>....<br><br>Right now, Im looking the documentation to find a way to do it, Im thinking about string methods, I also though: " hey, I just have to delete the 4 last characters, but na ! itll not work because sometime I have something like "_Fresnel_mat'' which is of course more than 4 chars...)<br>
<br>Maybe the best would be to declare something like "in the string, look at the last "_" and delete it + whatever there is after"<br>but I didnt find how to do it, I mean I tried splitext which is, not appropriate.<br>
<br>Do I have to declare a list of element like:<br>elementList: ["_ALB", "AMB", "_Beauty", etc...]<br>and to search that pattern in the files name to remove it after ? it seems not bad as solution, but I pretty sure there is a better way to do it.<br>
<br>right ?<br><br>anyway, thank very much guys ! :)<br>and have a good day !<br><br><br><div class="gmail_quote">2010/8/26 Peter Otten <span dir="ltr"><__<a href="mailto:peter__@web.de" target="_blank">peter__@web.de</a>></span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div>Alban Nona wrote:<br>
<br>
> Hi<br>
><br>
> So here is my problem:<br>
><br>
> I have my render files that are into a directory like this:<br>
><br>
> c:\log\renderfiles\HPO7_SEQ004_031_VDM_DIF_V001.0001.exr<br>
> c:\log\renderfiles\HPO7_SEQ004_031_VDM_DIF_V001.0002.exr<br>
> c:\log\renderfiles\HPO7_SEQ004_031_VDM_DIF_V001.0003.exr<br>
> ....<br>
> c:\log\renderfiles\HPO7_SEQ004_031_VDM_AMB_V001.0001.exr<br>
> c:\log\renderfiles\HPO7_SEQ004_031_VDM_AMB_V001.0002.exr<br>
> c:\log\renderfiles\HPO7_SEQ004_031_VDM_AMB_V001.0003.exr<br>
><br>
> True is, there is like 1000 Files is the directory (C:\log\renderfiles\)<br>
><br>
> What Iam looking to is to extract the first part of the filenames as a<br>
> list, but I dont want the script to extract it 1000times, I mean I dont<br>
> need it to extract HPO7_SEQ004_031_VDM_AMB 150 times, because there is 150<br>
> Frames. (not sure if its clear tought)<br>
><br>
> so far, I would like the list to look lik:<br>
><br>
> ["HPO7_SEQ004_031_VDM_DIF", "HPO7_SEQ004_031_VDM_AMB", etc...]<br>
><br>
><br>
> I start to think about that, to try to use a<br>
><br>
> for (path, dirs, files) in os.walk(path):<br>
> list.append(files)<br>
><br>
><br>
> but this kind of thing will just append the whole 1000 files, thing that I<br>
> dont want, and more complicated I dont want the thing after "AMB" or "DIF"<br>
> in the name files to follow.<br>
> (thing I can delete using a split, if I read well ?)<br>
><br>
><br>
> I trying to search on internet for answer, but seems I find nothing about<br>
> it.<br>
> Someone can help me with that please, show me the way or something ?<br>
<br>
</div></div>You can use glob. Assuming the files are all in one directory:<br>
<br>
import os<br>
import glob<br>
<br>
folder = r"C:\log\renderfiles"<br>
<br>
# find files that end with "_V001.0001.exr"<br>
pattern = os.path.join(folder, "*_V001.0001.exr")<br>
files = glob.glob(pattern)<br>
<br>
# remove the directory<br>
names = [os.path.basename(f) for f in files]<br>
<br>
# remove everything after and including the last occurence of "_"<br>
names = [n.rpartition("_")[0] for n in names]<br>
<br>
print "\n".join(sorted(names))<br>
<font color="#888888"><br>
Peter<br>
</font><div><div></div><div><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div></div></div><br>
</blockquote></div><br>