Oct-09-2020, 06:52 AM
Hello All
How to sort contents of the list I gathered from os.walk() method?
Here is my code:
./01 Course Welcome.mp4
./03 Using The Command Line.mp4
./Audience.mp4
./Binary to CAPITAL.MP4
./Binary to small.mp4
./Intro.mp4
./Intros.mp4
./_K24223951.mkv
./Tutorial.webm
./Alpha/Course introduction.mp4
./Alpha/Introduction to numbers.mp4
./Beta/Decimal to binary conversion.mp4
./Beta/Decimal to octal conversion.mp4
./Beta/beta1/Data Science Roles.mp4
./Beta/beta1/What is Data Science.mp4
./Beta/beta1/Why do we need Data Science.mp4
./Beta/beta1/Will Data Science be on Demand.mp4
./Theta/1. Introduction.mp4
./Theta/3. The Study Plan.mp4
./Theta/4. The Interface.mp4
./Theta/theta1/1. Organization of Job Search.mp4
./Theta/theta1/2. Job Search Sites.mp4
./Theta/theta1/theta2/01 - List, Create and Delete Partitions on MBR and GPT Disks.mp4
./Theta/theta1/theta2/02 - Create, Assign Physical Volumes to Volume Groups and Create and Delete Logical Volumes.mp4
./Theta/theta1/theta2/03 - Configure Systems to Mount File Systems at Boot by UUID or Label.mp4
./Theta/theta1/theta2/04 - Add New Partitions and Logical Volumes and Swap to a System Non-Destructively.mp4
Is this possible? Or am I expecting too much?
Thanks
How to sort contents of the list I gathered from os.walk() method?
Here is my code:
#!/usr/bin/env python3 import os EXTN = ['.avi', '.flv', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', '.webm', '.wmv'] videos_list = [] for root, dirs, files in os.walk('.'): for filename in files: for ext in EXTN: if filename.lower().endswith(ext.lower()): videos_list.append(os.path.join(root, filename)) for i in videos_list: print(i)And here is its output:
Output:./Binary to small.mp4
./01 Course Welcome.mp4
./Tutorial.webm
./Intro.mp4
./Audience.mp4
./Binary to CAPITAL.MP4
./Intros.mp4
./_K24223951.mkv
./03 Using The Command Line.mp4
./Beta/Decimal to binary conversion.mp4
./Beta/Decimal to octal conversion.mp4
./Beta/beta1/Will Data Science be on Demand.mp4
./Beta/beta1/What is Data Science.mp4
./Beta/beta1/Data Science Roles.mp4
./Beta/beta1/Why do we need Data Science.mp4
./Alpha/Introduction to numbers.mp4
./Alpha/Course introduction.mp4
./Theta/4. The Interface.mp4
./Theta/1. Introduction.mp4
./Theta/3. The Study Plan.mp4
./Theta/theta1/1. Organization of Job Search.mp4
./Theta/theta1/2. Job Search Sites.mp4
./Theta/theta1/theta2/01 - List, Create and Delete Partitions on MBR and GPT Disks.mp4
./Theta/theta1/theta2/03 - Configure Systems to Mount File Systems at Boot by UUID or Label.mp4
./Theta/theta1/theta2/04 - Add New Partitions and Logical Volumes and Swap to a System Non-Destructively.mp4
./Theta/theta1/theta2/02 - Create, Assign Physical Volumes to Volume Groups and Create and Delete Logical Volumes.mp4
Please note that the files within directory tree are not sorted. I want output be something like this../01 Course Welcome.mp4
./03 Using The Command Line.mp4
./Audience.mp4
./Binary to CAPITAL.MP4
./Binary to small.mp4
./Intro.mp4
./Intros.mp4
./_K24223951.mkv
./Tutorial.webm
./Alpha/Course introduction.mp4
./Alpha/Introduction to numbers.mp4
./Beta/Decimal to binary conversion.mp4
./Beta/Decimal to octal conversion.mp4
./Beta/beta1/Data Science Roles.mp4
./Beta/beta1/What is Data Science.mp4
./Beta/beta1/Why do we need Data Science.mp4
./Beta/beta1/Will Data Science be on Demand.mp4
./Theta/1. Introduction.mp4
./Theta/3. The Study Plan.mp4
./Theta/4. The Interface.mp4
./Theta/theta1/1. Organization of Job Search.mp4
./Theta/theta1/2. Job Search Sites.mp4
./Theta/theta1/theta2/01 - List, Create and Delete Partitions on MBR and GPT Disks.mp4
./Theta/theta1/theta2/02 - Create, Assign Physical Volumes to Volume Groups and Create and Delete Logical Volumes.mp4
./Theta/theta1/theta2/03 - Configure Systems to Mount File Systems at Boot by UUID or Label.mp4
./Theta/theta1/theta2/04 - Add New Partitions and Logical Volumes and Swap to a System Non-Destructively.mp4
Is this possible? Or am I expecting too much?
Thanks