Python glob and raw string

Xaxa Urtiz urtizvereaxaxa at gmail.com
Thu Jan 16 13:03:00 EST 2014


Le jeudi 16 janvier 2014 17:49:57 UTC+1, Xaxa Urtiz a écrit :
> Hello everybody, i've got a little problem, i've made a script which look after some files in some directory, typically my folder are organized like this :
> 
> 
> 
> [share]
> 
> folder1
> 
> ->20131201
> 
> -->file1.xml
> 
> -->file2.txt
> 
> ->20131202
> 
> -->file9696009.tmp
> 
> -->file421378932.xml
> 
> etc....
> 
> so basically in the share i've got some folder (=folder1,folder2.....) and inside these folder i've got these folder whose name is the date (20131201,20131202,20131203 etc...) and inside them i want to find all the xml files.
> 
> So, what i've done is to iterate over all the folder1/2/3 that i want and look, for each one, the xml file with that:
> 
> 
> 
> 
> 
> for f in glob.glob(dir +r"\20140115\*.xml"):
> 
> ->yield f
> 
> 
> 
> dir is the folder1/2/3 everything is ok but i want to do something like that :
> 
> 
> 
> 
> 
> for i in range(10,16):
> 
> ->for f in glob.glob(dir +r"\201401{0}\*.xml".format(i)):
> 
> -->yield f
> 
> 
> 
> but the glob does not find any file.... (and of course there is some xml and the old way found them...) 
> 
> Any help would be appreciate :)

I feel stupid, my mistake, it works :

for i in range(1,16):
->for f in glob.glob(dir +r"\201401{0:02}\*.xml".format(i)):
-->yield f



More information about the Python-list mailing list