1

00:00:00,160  -->  00:00:06,930
Work to 11:32 which roughly covers pages 197 to 200 of the automate the boring stuff with Python textbook

2

00:00:07,470  -->  00:00:11,780
and the previous lesson you learned how to create and write to new files in Python.

3

00:00:11,780  -->  00:00:15,720
Your programs can also organize pre-existing files on the hard drive.

4

00:00:15,900  -->  00:00:20,970
Maybe you've had the experience of going through a folder full of dozens hundreds or even thousands

5

00:00:20,970  -->  00:00:25,180
of files and having a copy rename or move them all by hand.

6

00:00:25,410  -->  00:00:31,870
All of that boring stuff is just begging to be automated by Python and the S.H. you.

7

00:00:31,890  -->  00:00:37,770
Or shell utilities module has functions that let you copy move rename and delete files in your Python

8

00:00:37,770  -->  00:00:43,680
programs then use the S.H. you till functions.

9

00:00:43,680  -->  00:00:49,350
First we'll have to import sh you till the first function we'll look at is the copy function.

10

00:00:49,350  -->  00:00:57,660
This will just copy a file to a new folder so we can type as you tell that copy and then specify one

11

00:00:57,660  -->  00:01:03,960
file and say I have spammed that to 60 right here

12

00:01:06,510  -->  00:01:13,000
inside the root folder so it's C colon slash spand at 60 and say it wanted to copy it to see colon slash

13

00:01:12,990  -->  00:01:13,020
.

14

00:01:13,020  -->  00:01:16,360
Delicious.

15

00:01:17,190  -->  00:01:23,640
I'll just pass the destination of where I want it to go will be in delicious and when I execute this

16

00:01:23,640  -->  00:01:28,690
function it will return the string of the copied files location.

17

00:01:28,690  -->  00:01:29,760
That's just a side effect.

18

00:01:29,760  -->  00:01:31,310
Usually we'll just ignore that.

19

00:01:31,320  -->  00:01:38,570
You can see that now there is a copy of spam that he XTi inside the delicious folder.

20

00:01:38,590  -->  00:01:45,120
Now you can also do a copy and rename at the same time by specifying a file name for the destination

21

00:01:45,120  -->  00:01:45,150
.

22

00:01:45,150  -->  00:01:52,460
So say I wanted to copy it to the delicious folder but also rename it to spam spam spam that text he

23

00:01:53,200  -->  00:01:57,350
needs to see now is copy that file but also giving it a name.

24

00:01:57,360  -->  00:02:00,330
Spam Spam spammed itx.

25

00:02:01,170  -->  00:02:06,360
So the copy function will work for copying a single file but what if you want it to copy an entire folder

26

00:02:06,480  -->  00:02:09,650
full of its own folders and files could use.

27

00:02:09,710  -->  00:02:14,810
You still try to copy tree and then just specify a folder.

28

00:02:14,820  -->  00:02:20,220
I'm going to say it's just a slightly delicious folder and all of the files and folders inside of it

29

00:02:20,490  -->  00:02:28,310
and I want to copy it as a new folder called Delicious backup.

30

00:02:29,880  -->  00:02:35,190
So now if we go back to the root folder you can see there's a new folder called Delicious backup and

31

00:02:35,190  -->  00:02:40,870
it has the same contents as the original delicious folder.

32

00:02:40,920  -->  00:02:47,340
Now we wanted to move a file to a new location move it to a different folder.

33

00:02:47,450  -->  00:02:53,040
SH still has a move function and the first string will be the file that you want to move.

34

00:02:53,040  -->  00:02:59,980
So say I wanted to move standard text he too delicious.

35

00:03:00,030  -->  00:03:04,690
Slash is a walnut folder inside of that delicious folder.

36

00:03:05,430  -->  00:03:11,450
So now this file no longer exists at this location instead it's been moved to this folder.

37

00:03:11,460  -->  00:03:16,770
You can see its new file path and name right here.

38

00:03:17,220  -->  00:03:23,790
You can go to the walnut folder here and we can see this Bampfylde is right here.

39

00:03:24,000  -->  00:03:25,310
Now if you want to do a rename.

40

00:03:25,380  -->  00:03:29,640
There is no rename function in SH you till.

41

00:03:29,670  -->  00:03:40,230
Instead what you do is you use the move function and that's fine that spam that text file and you rather

42

00:03:40,230  -->  00:03:43,010
you move it to the same folder that it's already in.

43

00:03:43,020  -->  00:03:44,210
But with a new name.

44

00:03:44,220  -->  00:03:50,110
This is kind of like what we did right here when we copied a file but also gave it a new name.

45

00:03:50,280  -->  00:03:57,090
Here we'll just move this file up its destination folder is going to be the same one as before and we'll

46

00:03:57,090  -->  00:04:01,950
just save it with a new name as well.

47

00:04:01,950  -->  00:04:05,730
So technically we're just moving it to the same folder but with a new name.

48

00:04:05,760  -->  00:04:08,280
And this has the effect of just renaming this file

49

00:04:11,740  -->  00:04:19,740
in C in the wish to slash walnut that spammed that TXU file has now been renamed to eggs that he XTi

50

00:04:22,980  -->  00:04:26,380
using the move function.

51

00:04:27,340  -->  00:04:35,370
So to recap as h util  dot copy will copy a file copy tree will copy a folder and all its content and

52

00:04:35,370  -->  00:04:39,410
move can move a file but also rename it as well.
