I have few main-directories with many subdirectories, I have to campare some information from my sub-s but only -vol with text file(I'm ok over here), my tree it looks like:
dir1-sub1
-...
-vol1
-vol2
-vol3
dir2-sub1
-...
-vol1
-vol2
-vol3
etc...
I want to use only vol2 everytime , im ok with that, I use inside -in os.walk and .startswitch() method - to get only vol2,
My problem is when some times vol2 is empty and I'cant do my action , have an error. That's a part of my script, I've tried it with try but not works and I'm blocked with that:
for dirname in os.listdir(path):
#print(dirname, "dirname")
#new_dirname = "#" + dirname
#print(new_dirname)
if dirname in open("F:\exif_time_packages_gopro\\BR.txt").read():
#print(dirname, " in list")
new_dirname = path + "\\" + dirname
print(new_dirname, "new")
for dir in os.listdir(new_dirname):
if dir.startswith('vol2'):
new_dir = new_dirname + "\\" + dir
print(new_dir)# I have all my vol2 over here <<<
empty = False
try:
if os.stat(new_dir).st_size > 0:
print("not empty",dir)
else:
print("empty sub")
except:
pass
My question is how can I switch a subdir when he is empty to vol1 and do my action in my loop, on this subdir vol1, how to use exception. Second question and problem is when I open vol2, I'm looking inside for file with name is "gpr" and sometimes ther are missing, how to write it when gpr, is missing pass to next dir. So I would like to check:
-if is empty(switch to vol1) and if have no gpr(pass)
-if not empty and gpr inside(do my action)
I don't know how to overwrite it, I've tried already few solution from here all day yesterday and nothing works.
Any help will be appreciated
Aucun commentaire:
Enregistrer un commentaire