Oct-22-2020, 03:38 PM
I don't understand your output at all. The code you show should be printing tuples with three elements, not strings...
import os my_path="tree" for dirs in os.walk(my_path): print (dirs)
Output:('tree', ['Beta', 'Theta', 'Alpha'], ['Tutorial.webm', '_K24223951.mkv', 'walker2.py', 'Intros.mp4', 'print_chars.py', 'walker.py', '03 Using The Command Line.mp4', 'Binary to CAPITAL.MP4', '01 Course Welcome.mp4', 'Intro.mp4', 'Binary to small.mp4', 'Audience.mp4'])
('tree/Beta', ['beta1'], ['Decimal to octal conversion.mp4', 'Decimal to binary conversion.mp4'])
('tree/Beta/beta1', [], ['Data Science Roles.mp4', 'Will Data Science be on Demand.mp4', 'Why do we need Data Science.mp4', 'What is Data Science.mp4'])
...
The first component is the directory you are in right now. The third component is the list of files in that directory. So examine the first one (dirpath) and see if the final component is "tests". If so, copy the files from that directory to where you want.