1
00:00:00,120 --> 00:00:08,700
In this video, we will write a script which gets all these text files and puts them inside a zip file.

2
00:00:09,840 --> 00:00:16,650
To do this, we will use the Path Objects and the Zip File Library, which is used to create a zip file,

3
00:00:17,310 --> 00:00:23,610
as usually we need the root directory, which is path where the files are in files.

4
00:00:24,240 --> 00:00:25,110
These directories here.

5
00:00:27,540 --> 00:00:36,960
And perhaps since we are a bonus to create one single zip file, then we need to create a path object

6
00:00:36,960 --> 00:00:38,460
for that zip file as well.

7
00:00:40,030 --> 00:00:42,790
So that would be path.

8
00:00:42,910 --> 00:00:48,820
Let's see, archive dot zip, that will be the name of the file.

9
00:00:49,150 --> 00:00:57,930
But if you want to put this file inside this directory inside files, then you want to add roots.

10
00:00:58,340 --> 00:01:00,670
Dear here with this flash.

11
00:01:01,360 --> 00:01:10,390
So the slash will concatenate these two to make the path like files slash archive that zip.

12
00:01:11,830 --> 00:01:18,520
And then what you do is you use the with context manager and say with zip file.

13
00:01:18,860 --> 00:01:25,870
So the library that zip file the class with a capital Z and the Capital F..

14
00:01:26,590 --> 00:01:30,910
And they say the parentheses goes the archive path.

15
00:01:32,480 --> 00:01:40,700
And now this has different modes when you want to create a zip file, you want to use the W modes,

16
00:01:40,700 --> 00:01:41,980
which means rights.

17
00:01:42,440 --> 00:01:45,470
And if you want to read so, then you use it, reads modes.

18
00:01:45,620 --> 00:01:50,540
The read mode would be when you extract an existing zip file, and we'll use that later.

19
00:01:51,230 --> 00:02:01,790
So as let's see as that's f, so that's f is the variable that holds this zip file object for now.

20
00:02:02,300 --> 00:02:07,400
So what do we do with this zip file object?

21
00:02:07,790 --> 00:02:11,810
Well, we perhaps we want to iterate through.

22
00:02:13,560 --> 00:02:26,180
Directory Gallup or Gallup and iterates over all those text files and for each of the files you want

23
00:02:26,180 --> 00:02:31,460
to see, that's right, that's file inside the zip file.

24
00:02:31,730 --> 00:02:35,390
So add text files to that zip file object.

25
00:02:36,530 --> 00:02:40,970
So Pathless added there, and I suppose that's it's.

26
00:02:42,560 --> 00:02:43,100
That's Iran.

27
00:02:44,090 --> 00:02:45,770
And here is a file.

28
00:02:46,520 --> 00:02:47,900
If you don't know that.

29
00:02:49,470 --> 00:02:54,240
And I extracted this on my computer, and I see all the files out here.

30
00:02:55,260 --> 00:02:55,590
Right.

31
00:02:57,180 --> 00:03:01,050
And that is how you can create an archive file.

32
00:03:01,990 --> 00:03:12,340
Now, if you don't want to keep the files in the directory, then you'd have to apply path dots on a

33
00:03:12,340 --> 00:03:13,180
link.

34
00:03:13,870 --> 00:03:15,130
So if I run this again?

35
00:03:16,330 --> 00:03:20,080
This time we get the archive file, but not the files.

36
00:03:20,230 --> 00:03:25,780
So what this does is it deletes a path, a file object, actually.

37
00:03:26,050 --> 00:03:30,610
So what we do here is we iterate through the directory.

38
00:03:31,420 --> 00:03:35,980
Let's say in the first iteration, we are working on the one file.

39
00:03:36,190 --> 00:03:44,770
We put that file inside the zip file and then we delete that 1.60 file using the unlink methods.

40
00:03:45,160 --> 00:03:51,040
And then the loop goes to the next iteration, writes with 2.60.

41
00:03:51,040 --> 00:03:53,410
It writes that it deletes its answer one.

42
00:03:54,130 --> 00:03:56,380
And that's about this video Let's have some more videos.

43
00:03:56,740 --> 00:03:57,490
Let's keep going.

