python - Iterating files in directory by name -


ok, have directory many files , subdirectories; among these ones there 20 directories called mbr001, mbr002, ... until mbr020 ones interested in.

i want write program iteratively goes mbr001, somethings, mbr002, same things, , on.

a solution python's os.chdir('./mbr001') until 20 seems pretty inefficient.

besides, when in such directories, let's example mbr012, want create variable has in name number of mbr am, in case 12. variable = 'mbr012_file.dat'. (this variable used in doing inside each directory, not relevant here).

what need (note pseudo-code):

for in mbr[i]:     variable = "mbr[i]_file.dat"     ... 

how can loop , variable naming? in advance.

what ?

for in range(1, 21):     dn =  "./mbr{:03}".format(i)     var = "mbr{:03}_file.dat".format(i)     os.chdir(dn)     # stuff here     #     #     os.chdir("..") 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -