using walk function in python -


i dealing folder hierarchy following:

c:/users/rox/halogen/iodine/(some .txt files) c:/users/rox/halogen/chlorine/(some .txt files) c:/users/rox/inert/helium/(some .txt files) c:/users/rox/inert/argon/(some .txt files) 

now iterating through out folder using os.walk , processing files.
problem if want generate analysis output folder 'halogen' after analyzing sub-folders under halogen should do... using:

for root,dirs,files in os.walk(path,'*.txt):     .....     .......[processing file]     out.write(.....)    # writing output in folder analyzing 

but how write output folder lies two-step back(i.e halogen or inert)..

you can open output file using relative path directory processing this:

for root, dirs, files in os.walk(path, '*.txt'):     out = open(os.path.join(root, '..', '..'), 'a')     out.write(...) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -