Aug-27-2020, 09:38 PM
You have a couple of problems. Your most serious is the logic on line 29. By precedence, it will be parsed as the following:
Your second issue is trying to remove elements from a list while you're using it as an iterator. The order gets messed up.
This should remove 2, 3, and 4 from the list, but fails because the iterator is upset.
if ("-sample") or ("-Sample" in j):As
"-sample"
is a string that is not empty, it is always true. This branch is always taken. If it's always taken, why is everything not removed?Your second issue is trying to remove elements from a list while you're using it as an iterator. The order gets messed up.
This should remove 2, 3, and 4 from the list, but fails because the iterator is upset.
>>> l = list(range(6)) >>> for i in l: ... if 2 <= i <= 4: ... l.remove(i) ... >>> print(l) [0, 1, 3, 5]While there are lots of ways around this (make a copy, use a comprehension to copy the bits you do want), an easier method here is to roll your exclusion into the previous loop. You don't have to remove something that you never stored in the first place.
for file in os.scandir(user_input): if "-sample" in file.name or "-Sample" in file.name: continue if file.name.endswith(('.mp4', '.mkv', '.avi')): list2.append(file.name)