1 00:00:00,000 --> 00:00:04,987 [MUSIC] 2 00:00:04,987 --> 00:00:06,118 Hi, I'm Kenneth. 3 00:00:06,118 --> 00:00:09,308 And in this course I'm going to show you how to use Python to take control of 4 00:00:09,308 --> 00:00:11,140 the files and directories on a computer. 5 00:00:11,140 --> 00:00:14,120 By the end of the course, you'll be able to use Python to check the size of files, 6 00:00:14,120 --> 00:00:16,080 create new files, rename directories, and more. 7 00:00:16,080 --> 00:00:19,590 Why would you want to use Python to do tasks that you normally do with your 8 00:00:19,590 --> 00:00:21,570 operating system's file explorer? 9 00:00:21,570 --> 00:00:24,370 Occasionally, you'll find yourself working on a system where you don't have any sort 10 00:00:24,370 --> 00:00:28,550 of visual file explore, like looking on a server or a microcontroller device. 11 00:00:28,550 --> 00:00:30,780 Or maybe you have a repetitive task like creating of files and 12 00:00:30,780 --> 00:00:32,147 directory structure for a project. 13 00:00:32,147 --> 00:00:34,434 And you're just sick and tired of doing it by hand. 14 00:00:34,434 --> 00:00:37,744 And even if none of that applies to you, knowing more about Python and 15 00:00:37,744 --> 00:00:40,780 how to use it for tasks like this is never a bad thing. 16 00:00:40,780 --> 00:00:42,710 This situations pop up when you least expect them. 17 00:00:43,860 --> 00:00:47,320 Before we get into the Python tools, and libraries and code, I want to take a few 18 00:00:47,320 --> 00:00:50,880 minutes to make sure your familiar with the terms we'll be using in this course. 19 00:00:50,880 --> 00:00:52,760 While I'm sure some of you are comfortable with these terms, 20 00:00:52,760 --> 00:00:55,160 it never hurts to have a bit of a refresher. 21 00:00:55,160 --> 00:00:59,030 Computers typically store data in files, whether these are text documents, images, 22 00:00:59,030 --> 00:01:00,670 movies or databases. 23 00:01:00,670 --> 00:01:04,280 Files have two major parts, their filename and their file type. 24 00:01:04,280 --> 00:01:06,810 Most of the time, the file type is reflected in the extension part of 25 00:01:06,810 --> 00:01:09,870 the filename, which is the part that comes after the dot in the filename. 26 00:01:10,880 --> 00:01:14,300 For example, a very common image format is the JPEG format. 27 00:01:14,300 --> 00:01:17,200 Most JPEG files have a .JPG file extension, 28 00:01:17,200 --> 00:01:19,300 which tells you that it is a JPEG file. 29 00:01:19,300 --> 00:01:20,150 The file extension, for 30 00:01:20,150 --> 00:01:23,180 the most part though, is just extra information for humans. 31 00:01:23,180 --> 00:01:26,660 Computers and software would use the file type, and not the extension to identify 32 00:01:26,660 --> 00:01:30,270 what kind of file a file is, when it needs to display or modify the file. 33 00:01:31,470 --> 00:01:33,410 Files are stored in Directories. 34 00:01:33,410 --> 00:01:36,120 It's become common parlance to call directories folders, and 35 00:01:36,120 --> 00:01:38,190 we usually have an icon of a folder to indicate them. 36 00:01:38,190 --> 00:01:39,490 But the actual name is directory. 37 00:01:39,490 --> 00:01:43,304 I will do my best to stick to using directory, but if I slip up, forgive me. 38 00:01:43,304 --> 00:01:45,176 Directories often form a tree of sort, 39 00:01:45,176 --> 00:01:48,480 with directories nested inside of directories. 40 00:01:48,480 --> 00:01:51,400 If I trace the directory tree all the way back though, 41 00:01:51,400 --> 00:01:54,130 I'll eventually come to the root directory, or location. 42 00:01:54,130 --> 00:01:56,670 On Windows, this is usually a drive name, like C. 43 00:01:56,670 --> 00:01:58,740 On a POSIX system, like Linux, Unix, 44 00:01:58,740 --> 00:02:02,790 or Mac OS through, It would be just a single slash that leans to the right. 45 00:02:02,790 --> 00:02:06,310 I'll use backslash for slashes that lean to the left like on Windows. 46 00:02:06,310 --> 00:02:09,060 And forward slash, or just slash for ones that lean to the right. 47 00:02:10,672 --> 00:02:12,760 When we talk about the location of a single directory or 48 00:02:12,760 --> 00:02:16,835 file, we call this collection of directory and file names its path. 49 00:02:16,835 --> 00:02:21,235 For example, if I have a file named my_next_course.py in my user's directory, 50 00:02:21,235 --> 00:02:28,402 it might have a path like this, C:\Users\Kenneth\my_next_course.py. 51 00:02:28,402 --> 00:02:31,432 Actually, let's talk about those slashes for a second, the official word for 52 00:02:31,432 --> 00:02:32,932 them is separators. 53 00:02:32,932 --> 00:02:36,302 On the Windows systems the slashes between directory and file names lean to left, 54 00:02:36,302 --> 00:02:38,562 every where else though they lean to the right. 55 00:02:38,562 --> 00:02:40,682 We call slashes that go to the left blackslashes, 56 00:02:40,682 --> 00:02:43,762 and those that go to the right forwardslashes or just slashes. 57 00:02:43,762 --> 00:02:47,430 If your typing out paths on these systems, be sure to use the correct slash. 58 00:02:47,430 --> 00:02:52,050 Python provides a system aware item named SEP, S-E-P, in the OS module 59 00:02:52,050 --> 00:02:56,140 to help you with this, but I'll show you how you can avoid dealing with it at all. 60 00:02:56,140 --> 00:02:59,340 In fact, we'll be using the OS library for most of this course. 61 00:02:59,340 --> 00:03:03,130 But like many Core Python modules the OS module is huge, and 62 00:03:03,130 --> 00:03:05,410 we won't be covering all of it in just this one course. 63 00:03:06,510 --> 00:03:08,830 If you're not comfortable moving around in your file system, 64 00:03:08,830 --> 00:03:12,140 check the teacher's notes for a link to our Console Foundations course. 65 00:03:12,140 --> 00:03:14,960 Otherwise, I think it's time to start looking at the tools we'll use to prune 66 00:03:14,960 --> 00:03:15,990 and grow our file tree.