Hi Everyone,
I am quite new in Python so probably an error is on my side, but I am not able to find out what is wrong:
# using c to have list of files in dir = 582 elements total
for a,b,c in os.walk('c:\\some\\path\\'):
pass
.
#some script - also removing elements from list here
.
.
print(c)
print("Keeping prefixes: pref1, pref2, pref2, pref4, pref5, pref6")
pref_list =["pref1","pref2","pref3","pref4","pref5","pref6"]
for entry in c:
for pref in pref_list:
print("dump: ", entry, " ", pref)
if pref == entry[:len(pref)]:
c.remove(entry)
print(entry, " not moved - prefix matched")
So I have list of prefixes and if file contains this prefix its removed from the list.
Once all files are matched again prefixes code continue to move rest of the files
in list to another directory.
Problem is that print(c) is showing also lists elements which for entry in c:
doesn’t loop through. I know it because print("dump: ", entry, " ", pref) should
print all loops in those 2 cycles. I tried to use sort() function, but some elements
which match prefix does not run in loop even they are visible in print(c).
Can anyone advise me what I am doing wrong ?
Thanks
btw - I have correct formating - not sure how to setup it here