0:00
Hey guys, welcome back to the next project
0:07
In this video, I'm going to create a Python program that will create a zip archive from
0:14
all of the mp3 files from the specified path. And inside of that archive, the folder structure, the directory structure will remain the same
0:26
like that of the normal folder. So without further ado, let's get going
0:32
First, I need to specify the encoding here. So encoding and that is UDF8
0:40
The next step is adding modules, adding required modules. So the first one I have is import OS
0:51
The second one I'll be using is zip file. The next step is to specify a path from where I want to get all of those mp3 files, all
1:02
of the mp3 files in a zip archive. So the path is here
1:08
Path equals to D and then I have a folder inside of it
1:15
Epson games. Well, that's the path. The next step is to create an empty archive, creating zip archive. Right
1:28
And we can store it that in a variable called ZF equals to zip file, dot zip file
1:37
So it has an attribute called zip file, which is in, which is in the capitalized case
1:43
And inside of these parentheses, you need to set that file name, that archive name basically
1:49
So it'd be mp3 archive, mp3 archive, dot zip. And the mod here is writing because we're going to write mp3 files to this empty archive
2:03
that I just created. The next step is collecting, collecting all mp3 files in the specified directory
2:13
So, well, you have to use for loop for, for their path, for their path
2:22
And the next one is their names. The last one is file names, file names in OS.walk
2:32
So OS has, OS module has an attribute called walk, which is basically returning three lists
2:40
The first list contains all directory paths. The second one contains directory names
2:47
And the last one will contain all of the file names in the specified directory here
2:54
So the specified, I'm going to specify the directory that is path, right
3:00
Because the path variable contains the actual path. So they specify that
3:05
And now what is the next step here? Well, using another loop here for I and file names
3:13
We're only concerned with the file names because if you have the file name, you can easily
3:19
identify whether we have an mp3 file or not. So if I.endsWith, I.endsWith dot mp3 extension, right
3:35
So what you need to do is to simply append that, Zedf dot write, append that file, which
3:44
will have a path right in this directory path. So directory path plus double backslashes because we're going to complete the path
3:54
And then I here. And you need to store it inside of that archive
4:02
But to the help of this path, I'm specifying again here will help us to keep the same directory structure
4:11
So here we go. Well, it's done now. Simply at last, we need to close that archive or that file
4:21
So closing, closing, closing file, Zedf dot close
4:32
There we go, guys. Now it's time to run this code. If you still have any questions regarding this code, you can ask me in comments and
4:41
to get the source code of this program, just go to the description and follow the link
4:46
You can easily grab it
4:58
And as you can see, this archive is finally here
5:09
So let's open it up and see if it contains only mp3 files
5:14
So as you can see, I'm going to open this folder. You can see this is an mp3 file and inside of it we have several folders
5:22
The first one contains also mp3 files. Let's get back to Windows one
5:27
And it has another one and inside of this folder we've got another one
5:31
So that was all guys. Hopefully you guys enjoyed this video. If you did, give it a thumbs up, subscribe me for more awesome content and I will see