1 00:00:00,000 --> 00:00:02,300 Friends, here we are going to 2 00:00:02,300 --> 00:00:05,900 work with 'os.walk'. See this 'walk' is 3 00:00:05,900 --> 00:00:10,400 a method from your 'os', and it is used to generate directory 4 00:00:10,400 --> 00:00:13,500 and file names in a directory tree by walking. 5 00:00:14,900 --> 00:00:19,900 See simply in case if you are familiar with Unix-like systems, 6 00:00:20,000 --> 00:00:24,200 and if you know 'find' command, right, suppose if I run something 7 00:00:24,200 --> 00:00:27,400 like 'find path -name *', 8 00:00:27,600 --> 00:00:28,600 let's say some 9 00:00:30,000 --> 00:00:31,000 '.txt', 10 00:00:31,000 --> 00:00:33,000 [no audio] 11 00:00:33,000 --> 00:00:35,600 so what it will do? Your 'find' command 12 00:00:35,600 --> 00:00:41,000 will recursively look for text files from the given path. 13 00:00:41,900 --> 00:00:44,900 Means, assume that you are giving a path like this something 14 00:00:44,900 --> 00:00:49,600 like, some 'xyz' user you are giving. Then first 15 00:00:49,600 --> 00:00:52,200 it will look for your text files in this path. 16 00:00:52,300 --> 00:00:56,000 Then if there are any directories, let's say I have a 'dir1', 17 00:00:56,000 --> 00:00:59,500 then automatically your 'find' command will create a path 18 00:00:59,500 --> 00:01:02,500 called '/home/xyz/dir1', and in that also it will try 19 00:01:02,500 --> 00:01:05,500 to look for text files. And assume that in 'dir1' 20 00:01:05,500 --> 00:01:07,700 also you have some directories, 21 00:01:08,300 --> 00:01:13,700 let's say 'sub1', then in that location 22 00:01:13,700 --> 00:01:15,400 also it will try to look for '*', 23 00:01:15,800 --> 00:01:17,100 I mean any text files. 24 00:01:18,300 --> 00:01:20,100 So from the given path it is going 25 00:01:20,100 --> 00:01:24,400 to look for some text files recursively, that means all 26 00:01:24,400 --> 00:01:27,300 the possibility paths whatever you have inside of your path, 27 00:01:27,500 --> 00:01:29,300 recursive paths, in all those paths 28 00:01:29,300 --> 00:01:33,200 it will try to look for your '.txt' files. That's fine. 29 00:01:33,600 --> 00:01:37,000 So the same way you're going to work with your 'os.walk' as well. 30 00:01:37,400 --> 00:01:39,800 But in case if you don't know about 'find' command, don't worry, 31 00:01:39,800 --> 00:01:41,600 here we are going to discuss about it. 32 00:01:43,000 --> 00:01:45,100 Guys, let me take some path. 33 00:01:45,200 --> 00:01:51,700 I am going to take a path called, let me take, yeah, this is a path. 34 00:01:52,400 --> 00:01:55,200 Okay. Now, I'm going to write a simple Python script. 35 00:01:55,200 --> 00:02:01,600 [no audio] 36 00:02:01,600 --> 00:02:03,200 Okay. Let me write any script name. 37 00:02:03,200 --> 00:02:06,400 I have given script name as 'os.walk.py'. Okay, 38 00:02:06,400 --> 00:02:08,000 'os_walk.py'. 39 00:02:08,800 --> 00:02:10,500 Let me take a path called, 40 00:02:11,400 --> 00:02:12,800 this one. Right. 41 00:02:12,800 --> 00:02:15,200 Just now we copied. We know we are working with the Windows, 42 00:02:15,200 --> 00:02:17,600 we have to provide '\\' in your path, 43 00:02:17,600 --> 00:02:21,700 otherwise because of special characters you may get error. 44 00:02:23,300 --> 00:02:24,600 Right. Fine. 45 00:02:26,300 --> 00:02:28,300 Now let me directly print your 46 00:02:28,300 --> 00:02:30,100 [no audio] 47 00:02:30,100 --> 00:02:35,500 'os.walk', then your given path, and we are using here 'os' module, 48 00:02:35,600 --> 00:02:38,700 so before using it you have to import it, and it's better to 49 00:02:38,900 --> 00:02:42,400 import at very first line. That is actually better practice. 50 00:02:43,400 --> 00:02:47,700 Fine. Now, I am running. You're getting some output, and this 51 00:02:47,700 --> 00:02:49,200 is a 'generator' object. 52 00:02:49,800 --> 00:02:52,800 You can also convert your object into list because this output 53 00:02:52,800 --> 00:02:54,500 is finally going to give a list. 54 00:02:54,500 --> 00:02:58,300 That's why I am trying to convert this as a list. Now see 55 00:02:58,300 --> 00:02:59,400 the output what you are getting. 56 00:02:59,400 --> 00:03:01,400 [no audio] 57 00:03:01,400 --> 00:03:06,700 First of all from your given path Python is generating a 58 00:03:06,700 --> 00:03:11,900 list which consists of tuples, and each tuple consists of 59 00:03:12,000 --> 00:03:13,700 three values. Be clear. 60 00:03:14,900 --> 00:03:18,000 'os.walk' is always going to generate a list, assume 61 00:03:18,000 --> 00:03:20,200 that. Actually that is a 'generator' object, but you can convert 62 00:03:20,200 --> 00:03:23,000 that into a list. Now, it is very easy 63 00:03:23,000 --> 00:03:25,300 if you remember in this way. 'os.walk' is going to 64 00:03:25,300 --> 00:03:29,300 generate a list first, and that list consists of tuples. 65 00:03:29,900 --> 00:03:32,800 See that, this is a tuple no, and that tuple consists 66 00:03:32,800 --> 00:03:37,700 of three values. First value is always the path which you have given, 67 00:03:38,800 --> 00:03:43,000 and second is a list, third is also a list, and 68 00:03:43,000 --> 00:03:46,300 this list is list of directories in the given list, in the 69 00:03:46,300 --> 00:03:50,200 given path. In this path, the list of directories you will 70 00:03:50,200 --> 00:03:53,900 get here. Here you will get the list of files in a given directory. 71 00:03:54,000 --> 00:03:56,600 Automatically your Python is separating, 72 00:03:57,600 --> 00:04:01,200 right, your list of directories and list of files for your given path. 73 00:04:01,200 --> 00:04:03,400 [no audio] 74 00:04:03,400 --> 00:04:06,200 Right. Let me take other path. 75 00:04:06,700 --> 00:04:10,400 So I am going to take a path called suppose, 'programming', 76 00:04:10,400 --> 00:04:12,300 [no audio] 77 00:04:12,300 --> 00:04:14,300 some different path, in that path 78 00:04:14,300 --> 00:04:16,100 I have only files, right? 79 00:04:16,100 --> 00:04:18,600 Anyway I have only one file. If you want to create one more 80 00:04:18,600 --> 00:04:23,200 file, let me create 'x.txt', 'y.py', something like that. 81 00:04:23,700 --> 00:04:25,200 Now you have three files here. 82 00:04:26,000 --> 00:04:27,800 Okay. Instead of 'scripting', 83 00:04:27,800 --> 00:04:30,200 let me take different path. Now 84 00:04:30,200 --> 00:04:31,700 I am going to run. See the output. 85 00:04:33,200 --> 00:04:35,800 Still you don't have any directories, but you have files 86 00:04:35,800 --> 00:04:36,900 in the given location. 87 00:04:36,900 --> 00:04:39,000 Now your Python is able to identify them. 88 00:04:39,000 --> 00:04:41,400 [no audio] 89 00:04:41,400 --> 00:04:46,700 Right. Now, let me take one directory here. 90 00:04:46,700 --> 00:04:48,700 [no audio] 91 00:04:48,700 --> 00:04:50,500 Let me create directory, 92 00:04:52,900 --> 00:04:57,100 some 'hello' directory. Right. Now in your 'programming', 93 00:04:57,200 --> 00:04:59,500 you have a directory. Right. 94 00:05:00,300 --> 00:05:02,200 Okay. Let me run it and see the output. 95 00:05:02,200 --> 00:05:04,600 [no audio] 96 00:05:04,600 --> 00:05:09,300 You're getting two paths. One path is your given path. Be clear. 97 00:05:09,700 --> 00:05:12,500 This is what your 'os.walk' is walking, doing. 98 00:05:13,900 --> 00:05:15,300 In your given path 99 00:05:16,300 --> 00:05:20,100 you have one directory and three files. That is over, 100 00:05:20,100 --> 00:05:23,300 whatever the path you are giving. But your Python will recursively 101 00:05:23,300 --> 00:05:24,800 search from there onwards. 102 00:05:26,100 --> 00:05:30,100 See, because 'hello' is there, if I add 'hello' path to this path, 103 00:05:30,100 --> 00:05:31,600 then you can create one new path. 104 00:05:32,100 --> 00:05:33,300 That's what Python is doing. 105 00:05:33,700 --> 00:05:37,200 Automatically this 'hello' is going to add to your given path. 106 00:05:37,300 --> 00:05:40,400 The new path it is adding no. New directory path is there. 107 00:05:40,800 --> 00:05:42,400 Now in that new directory path 108 00:05:43,000 --> 00:05:45,100 it is going to list directories and files. 109 00:05:45,100 --> 00:05:46,700 As of now we don't have anything. 110 00:05:47,500 --> 00:05:50,300 Let me create one more directory and see the result. 111 00:05:50,300 --> 00:05:54,600 [no audio] 112 00:05:54,600 --> 00:05:56,100 Sorry, that is a file, right? 113 00:05:57,300 --> 00:06:00,500 Let me create one more directory, it's already there. 114 00:06:02,100 --> 00:06:03,100 Yeah. 115 00:06:03,100 --> 00:06:05,500 [no audio] 116 00:06:05,500 --> 00:06:07,600 Oh. Okay fine. 117 00:06:09,200 --> 00:06:11,500 Now let me rerun and see the output. 118 00:06:12,500 --> 00:06:15,700 Guys, if you observe clearly for your given path, 119 00:06:15,700 --> 00:06:19,600 first of all your Python is giving this as your path, and 120 00:06:19,600 --> 00:06:22,900 in that path the list of directories, and then in this path 121 00:06:22,900 --> 00:06:27,400 list of files. That is over with one step. But if you add 122 00:06:27,400 --> 00:06:31,300 these two directories to your given path, what will happen? 123 00:06:31,900 --> 00:06:34,600 New directory path will be coming up. 124 00:06:35,200 --> 00:06:39,400 So yes, you are able to form new directory paths. 125 00:06:39,400 --> 00:06:42,800 Now Python will automatically form that, and in that 126 00:06:42,800 --> 00:06:46,500 if you have any directories and list, it will list out. Right. The same way 127 00:06:46,500 --> 00:06:49,700 it is forming two paths with 'byee' one path, 128 00:06:49,700 --> 00:06:53,500 'hello' one path. Suppose inside of your 'byee', or 'hello' 129 00:06:53,500 --> 00:06:59,000 if you have one more directory, let me travel into my 'hello', 130 00:06:59,900 --> 00:07:01,500 as of now we don't have anything here. 131 00:07:03,200 --> 00:07:06,200 Right. What I am doing is, first I am going to create a file called, 132 00:07:07,200 --> 00:07:08,300 'hello.py'. 133 00:07:10,000 --> 00:07:11,300 'hello.txt'. 134 00:07:12,600 --> 00:07:16,200 Right. See, previously with your 'hello' directory path, 135 00:07:16,200 --> 00:07:18,700 you don't have any files here, right. Now, 136 00:07:19,000 --> 00:07:23,900 I have files, two files, right. See that. Now, let me run our 137 00:07:23,900 --> 00:07:25,200 script and see the result. 138 00:07:26,700 --> 00:07:28,600 Now you've got two files automatically. 139 00:07:28,600 --> 00:07:31,600 [no audio] 140 00:07:31,600 --> 00:07:33,700 And here I don't have any directories. 141 00:07:33,700 --> 00:07:34,900 Let me create a directory, 142 00:07:35,900 --> 00:07:36,900 'hello1'. 143 00:07:36,900 --> 00:07:38,800 [no audio] 144 00:07:38,800 --> 00:07:42,300 Now see the result. You're going to get one directory here, 145 00:07:42,300 --> 00:07:46,300 at the same time because this is a directory, this directory 146 00:07:46,300 --> 00:07:48,800 your Python is going to add to this path, and it is going to 147 00:07:48,800 --> 00:07:50,400 form a new directory path, 148 00:07:51,400 --> 00:07:54,000 that means all possibility paths 149 00:07:54,000 --> 00:07:57,500 it is going to form automatically the path which you have 150 00:07:57,500 --> 00:08:00,600 given from that. See that, 'hello' directory, 151 00:08:00,600 --> 00:08:04,100 'hello1' directory, in that two files. But this directory 152 00:08:05,200 --> 00:08:10,000 if you add to this path, then you are able to create new directory 153 00:08:10,000 --> 00:08:11,300 path. That's what Python is doing 154 00:08:11,300 --> 00:08:13,900 when it is giving a list of files and directories. But we don't 155 00:08:13,900 --> 00:08:15,300 have anything here. Likewise, 156 00:08:15,800 --> 00:08:20,200 if you give any path, from that path your Python is automatically 157 00:08:21,800 --> 00:08:25,900 forming all possible paths, and each and every path 158 00:08:25,900 --> 00:08:29,100 it is going to provide list of directories and list of files. 159 00:08:30,100 --> 00:08:33,100 Now assume that, observe that, whatever the output you are 160 00:08:33,100 --> 00:08:34,900 getting that is a list. Be clear. 161 00:08:34,900 --> 00:08:40,299 Basically, this is the list symbol, right. In that list 162 00:08:40,400 --> 00:08:45,299 if you observe, you have a tuple, this is a symbol, right? 163 00:08:45,900 --> 00:08:47,500 And this is up to this one only. 164 00:08:47,600 --> 00:08:51,700 This is the first tuple in a list, and this is the second tuple, 165 00:08:52,400 --> 00:08:54,700 and this is a third tuple, fourth tuple. 166 00:08:56,400 --> 00:08:59,500 See if you have a list, right, 167 00:08:59,700 --> 00:09:02,100 you can take one by one using your loop. 168 00:09:02,600 --> 00:09:03,900 That's why what I am doing is, 169 00:09:05,500 --> 00:09:06,700 instead of printing in this 170 00:09:06,700 --> 00:09:09,000 way, okay, otherwise I will do one thing. 171 00:09:09,000 --> 00:09:11,500 I will keep this as it is. Again, 172 00:09:11,500 --> 00:09:13,900 I will apply for loop, 'for each in' your 173 00:09:15,300 --> 00:09:17,900 'list(os.walk 174 00:09:20,100 --> 00:09:21,100 (path))'. 175 00:09:21,800 --> 00:09:24,300 Let me print your 'each' and see the output. 176 00:09:25,000 --> 00:09:26,000 Try to understand. 177 00:09:27,400 --> 00:09:29,700 See guys, let me differentiate them. 178 00:09:29,700 --> 00:09:35,200 [no audio] 179 00:09:35,200 --> 00:09:38,700 See in your first output, 'os.walk(path)', directly 180 00:09:38,700 --> 00:09:42,700 I am printing. In that this is first tuple value. 181 00:09:43,900 --> 00:09:47,700 In your list this is the one value. I am able to separate them using for 182 00:09:47,700 --> 00:09:50,300 loop. Same way second. 183 00:09:51,400 --> 00:09:55,200 Now I am printing separately your tuple values from your 184 00:09:55,200 --> 00:09:59,900 list. And one more thing because this is a generator you 185 00:09:59,900 --> 00:10:03,200 are converting that into list just to see and to understand 186 00:10:03,200 --> 00:10:06,400 by you, but Python can understand that without converting 187 00:10:06,400 --> 00:10:09,000 into a list. Now see that, I am removing this list. 188 00:10:10,300 --> 00:10:13,600 List operation I am removing. And if I run, see the output. 189 00:10:13,800 --> 00:10:15,800 Same output, means Python can understand that 190 00:10:15,800 --> 00:10:17,500 what is there inside of your generator? 191 00:10:17,800 --> 00:10:21,100 Actually, that is a generator object, right. Python can understand 192 00:10:21,100 --> 00:10:24,900 that. That's why you're getting this all possibility tuple 193 00:10:24,900 --> 00:10:30,200 values. So you are getting four tuples. Right. Fine. 194 00:10:30,200 --> 00:10:33,300 Now, let me comment your 'print' statement, and observe the output. 195 00:10:34,800 --> 00:10:38,900 Four tuples you're getting, right. Guys in each tuple 196 00:10:38,900 --> 00:10:42,800 if you observe you have three values - one is the path, and 197 00:10:42,800 --> 00:10:44,100 second one is in this path 198 00:10:44,100 --> 00:10:47,200 what are the list of directories, and third one is in that 199 00:10:47,200 --> 00:10:49,000 path what are the list of files. 200 00:10:50,100 --> 00:10:52,400 Yes, you are getting, right. Now, 201 00:10:53,500 --> 00:10:56,700 if we have three values in your tuple, let me show you that. 202 00:10:56,700 --> 00:10:59,100 [no audio] 203 00:10:59,100 --> 00:11:00,400 Try to follow step-by-step. 204 00:11:01,500 --> 00:11:03,600 Let's say I have a tuple called in this way. 205 00:11:04,800 --> 00:11:08,700 'x=(3, 4, 5)'. Then if you print 'x', we are getting in this way. 206 00:11:08,700 --> 00:11:11,200 But '(3,4,5)' directly 207 00:11:11,200 --> 00:11:15,100 I can assign to three variables, and see the 'y' value or 'z' 208 00:11:15,200 --> 00:11:16,400 value or 'x' value. 209 00:11:17,100 --> 00:11:22,700 You can unpack your tuple directly into a number of variables, 210 00:11:23,100 --> 00:11:26,700 but while assigning in this way the values which you have in the tuple, 211 00:11:26,700 --> 00:11:30,700 the number of values should be the number of variables so 212 00:11:30,700 --> 00:11:31,700 that you can unpack. 213 00:11:32,500 --> 00:11:33,700 Now what I am doing 214 00:11:33,700 --> 00:11:36,500 is, if you observe your output in your script, 215 00:11:37,600 --> 00:11:41,200 the first one is some given path, right, or assume that 216 00:11:41,200 --> 00:11:42,300 this is a root path. 217 00:11:42,500 --> 00:11:44,700 I mean, whatever the path you are giving that's just assumption, 218 00:11:44,700 --> 00:11:47,500 root path. Then in that path, directories list, 219 00:11:47,500 --> 00:11:49,300 in that path files list. 220 00:11:49,800 --> 00:11:54,200 So now this is a tuple, whatever the value you are printing 221 00:11:54,200 --> 00:11:57,200 using your for loop, each and every value is a tuple. 222 00:11:57,200 --> 00:11:58,400 Now, what I am doing is, 223 00:11:58,400 --> 00:12:00,400 [no audio] 224 00:12:00,400 --> 00:12:04,100 directly here itself I'm unpacking. See instead of 'each' 225 00:12:04,100 --> 00:12:07,400 what I am taking is your root path, directories list, and then 226 00:12:07,400 --> 00:12:09,900 files list. You can also take lengthy variables. 227 00:12:09,900 --> 00:12:14,000 I don't want to take in this way like 'root', 'dir_list', 228 00:12:15,700 --> 00:12:19,300 'files_list', I don't want to take this lengthy variables. Simply 229 00:12:19,300 --> 00:12:23,100 I want to take like root, and these are not the fixed variables. 230 00:12:23,100 --> 00:12:24,400 You can take any variables. 231 00:12:24,400 --> 00:12:26,700 [no audio] 232 00:12:26,700 --> 00:12:27,700 That's it. 233 00:12:28,800 --> 00:12:32,700 Now if I print all these three you are getting your tuple. Right. Now, 234 00:12:32,700 --> 00:12:36,100 what I am doing is, I am printing only 'r', then you can expect 235 00:12:36,100 --> 00:12:39,200 from each and every tuple you're going to print this first 236 00:12:39,200 --> 00:12:43,000 path. That means all the possible paths you are printing 237 00:12:44,500 --> 00:12:45,900 Let me run it and see the output. 238 00:12:47,000 --> 00:12:49,300 You're printing only all possible paths. 239 00:12:50,700 --> 00:12:52,700 Now I want to print each and every path, 240 00:12:52,800 --> 00:12:57,000 what are the files list, only files list. The path, in that 241 00:12:57,000 --> 00:13:02,000 path what are the files. See that 'r, f'. That's it. 242 00:13:02,900 --> 00:13:05,500 If you have, you will get it. If you don't have, it won't display that. 243 00:13:06,500 --> 00:13:10,400 Now I want to get each path, in that path only directories list. 244 00:13:11,800 --> 00:13:12,800 See that. 245 00:13:12,800 --> 00:13:15,000 [no audio] 246 00:13:15,000 --> 00:13:16,000 Fine. 247 00:13:16,600 --> 00:13:21,000 Okay. If it is fine, now let's come back with again files. 248 00:13:21,000 --> 00:13:28,000 [no audio] 249 00:13:28,000 --> 00:13:32,600 See the output. The path from you, guys 250 00:13:32,600 --> 00:13:35,300 first of all you're getting your given path, in that path 251 00:13:35,500 --> 00:13:36,500 list of files. 252 00:13:36,900 --> 00:13:38,400 I have one more option here. 253 00:13:38,400 --> 00:13:40,300 [no audio] 254 00:13:40,300 --> 00:13:41,900 'topdown = 255 00:13:43,300 --> 00:13:46,500 'False', and in this case, what is the output, just observe that. 256 00:13:48,100 --> 00:13:49,900 You are reversing your output. 257 00:13:50,500 --> 00:13:54,000 So your Python is going to get from bottom to top values. 258 00:13:55,600 --> 00:13:57,100 By default it is always 'True'. 259 00:13:57,100 --> 00:13:58,100 'topdown' is 'True'. 260 00:13:58,300 --> 00:13:59,700 Even if you write no problem. 261 00:13:59,700 --> 00:14:02,700 Even if you don't write no problem. See if you write you're 262 00:14:02,700 --> 00:14:08,900 getting suppose 'bye', 'ok' first. That is by default. If you want 263 00:14:08,900 --> 00:14:10,800 to make it as 'topdown' as 'False'. 264 00:14:10,800 --> 00:14:14,600 I mean, I want to get output from down to 'false'. In your directory 265 00:14:14,600 --> 00:14:17,500 structure, suppose assume that this is a given directory. In that 266 00:14:17,500 --> 00:14:20,600 you have some number of directories and then number of files. 267 00:14:20,900 --> 00:14:22,800 Again in this you have some directories 268 00:14:24,300 --> 00:14:26,200 and files. Again in this directory you have 269 00:14:26,200 --> 00:14:28,000 some number of directories and files. 270 00:14:28,900 --> 00:14:30,800 So this is top-down. In this way 271 00:14:30,800 --> 00:14:34,300 your Python will look by default. In case if you want to print 272 00:14:34,300 --> 00:14:39,400 your paths from down to top, then you have to make it 273 00:14:39,400 --> 00:14:40,900 'topdown' value as 'False', 274 00:14:40,900 --> 00:14:43,900 so that your Python will give first this list, then come back, 275 00:14:43,900 --> 00:14:46,900 then come back, then your top. That's it. 276 00:14:47,400 --> 00:14:50,500 But it's not, I mean not a required method. If you want 277 00:14:50,500 --> 00:14:52,500 you can mention this option, right? 278 00:14:53,600 --> 00:14:54,600 That's fine. 279 00:14:55,600 --> 00:14:59,500 Okay. Now you are getting your path, in that path 280 00:14:59,500 --> 00:15:00,800 you have your files. 281 00:15:02,300 --> 00:15:07,500 Right. Now I want to print the path which consists of some files. 282 00:15:08,400 --> 00:15:12,000 I don't want to print all the paths which are not having 283 00:15:12,700 --> 00:15:18,600 files. Then what I will do? See that. 'if len(f)', 284 00:15:19,300 --> 00:15:22,900 if it is not equal to 0, if it is 0 I don't want to print, 285 00:15:22,900 --> 00:15:26,800 if it is not equal to 0 then only print. See that, you are 286 00:15:26,800 --> 00:15:30,000 getting only two paths which are having your files. Previously 287 00:15:30,000 --> 00:15:33,700 you got four paths, right, but now you're getting only two paths. Because 288 00:15:33,700 --> 00:15:35,000 I have given a condition, 289 00:15:36,100 --> 00:15:40,100 print the files, print the path and files which are having, 290 00:15:40,100 --> 00:15:42,300 I mean the path which are having some files. 291 00:15:42,900 --> 00:15:45,300 So what I am doing is, now first of all you know you are able 292 00:15:45,300 --> 00:15:47,500 to find your list of files in a given path. 293 00:15:48,000 --> 00:15:50,700 Then I'm finding length. If length is not equal to 0 means 294 00:15:50,700 --> 00:15:53,100 you have at least one file. Then I am printing that. 295 00:15:54,200 --> 00:15:56,600 Right. Fine. Now 296 00:15:58,300 --> 00:16:03,500 I don't want to print, I don't want to print my files as a list. 297 00:16:05,200 --> 00:16:07,900 I want to print my files one by one. 298 00:16:09,000 --> 00:16:11,600 First what I am doing is, I am printing my root path. 299 00:16:12,600 --> 00:16:15,400 Right. Now let me print first separately your files. Guys, 300 00:16:15,400 --> 00:16:18,000 I'm going with step-by-step. The same way you just practice, 301 00:16:18,000 --> 00:16:18,900 and observe the output. 302 00:16:20,000 --> 00:16:21,400 I am getting my root path, 303 00:16:21,900 --> 00:16:25,500 I mean for these two files whatever the path is there. Then 304 00:16:25,500 --> 00:16:30,000 for these files, whatever the path, path and it's files I am getting. Now, 305 00:16:30,000 --> 00:16:33,400 I want to get, I want to display one by one file under 306 00:16:33,400 --> 00:16:34,500 your given path. 307 00:16:35,100 --> 00:16:37,200 Nothing is there. You can take for loop here again. 308 00:16:37,200 --> 00:16:40,000 'for each_file in f', 309 00:16:40,000 --> 00:16:43,500 just simply print your 'each_file'. See the output. 310 00:16:43,500 --> 00:16:46,500 [no audio] 311 00:16:46,500 --> 00:16:51,700 Now what I want to do is, I want to get complete path for my each and 312 00:16:51,700 --> 00:16:54,400 every file. It's very, very important. 313 00:16:56,000 --> 00:16:59,600 I want to get each and every, each and every file 314 00:16:59,600 --> 00:17:05,098 I want to get complete path. See guys if you clearly observe, 315 00:17:05,500 --> 00:17:09,400 in this path only you have your files, right. If I add this path 316 00:17:09,400 --> 00:17:10,400 to your 'each_file', 317 00:17:10,400 --> 00:17:12,000 you're going to form complete path. 318 00:17:12,800 --> 00:17:16,400 So this scenario is very, very important in your real time. 319 00:17:17,500 --> 00:17:23,098 Nothing is there. Directly you can print 'os.path.join', 320 00:17:23,000 --> 00:17:25,200 your root, then your file. 321 00:17:25,200 --> 00:17:27,700 [no audio] 322 00:17:27,700 --> 00:17:29,400 It's very simple. See the output. 323 00:17:31,099 --> 00:17:34,099 You are getting your root path in that, I mean root path, 324 00:17:34,400 --> 00:17:36,900 now I am getting complete path for my each and every file. 325 00:17:39,500 --> 00:17:43,099 Right. Just for your differentiation between different paths 326 00:17:43,099 --> 00:17:44,500 I am writing here hyphens. 327 00:17:45,900 --> 00:17:46,900 Now see the output. 328 00:17:47,800 --> 00:17:51,599 This is your main path, in that the files, but I am getting 329 00:17:51,599 --> 00:17:52,599 with complete path. 330 00:17:52,700 --> 00:17:57,600 That's what actually I need. It's very, very important. Then 331 00:17:57,600 --> 00:18:01,100 second path and in that path I have list of files. 332 00:18:02,800 --> 00:18:05,300 Right. Fine. 333 00:18:05,300 --> 00:18:09,300 So guys, whatever the concept we've done in this video, 334 00:18:09,500 --> 00:18:12,900 this is applicable even for your Unix-like systems. 335 00:18:13,600 --> 00:18:16,900 Okay. So in next video, we will see with practice, 336 00:18:17,600 --> 00:18:18,900 with real-time practice. 337 00:18:19,600 --> 00:18:22,300 Okay. Okay guys, thank you for watching this video. 338 00:18:22,300 --> 00:18:33,173 [no audio]