Search code examples
pythonpython-2.7directoryglobos.walk

Access file placed in multiple directories via python


I have two paths and in between one directory is variable. i want to access the xml file and make some changes with python script. how can i achieve this ?

p1  = '/opt/apache-tomcat-8.0.33/webapps/'
p2 = '/WEB-INF/classes/j2.xml'

full path looks like this :

/opt/apache-tomcat-8.0.33/webapps/text1/WEB-INF/classes/j2.xml
/opt/apache-tomcat-8.0.33/webapps/`abc2`/WEB-INF/classes/j2.xml

I have couple of files, placed in same manner. please help me on this. i tried to use blob i could not achieve the expected result.


Solution

  • from glob import glob
    
    p1  = '/opt/apache-tomcat-8.0.33/webapps/'
    p2 = '/WEB-INF/classes/j2.xml'
    
    print(glob(p1+'*'+p2))