 Hey everybody it's Brian, welcome to the 13th Python tutorial. We're going to be listing directory contents. Now we want to get everything in a directory. Sometimes this is handy and we can do that by, let's first just, my eyes are kind of bothering me today. I have to apologize if I make spelling mistakes. I had my post op, I had, whoops, I had eye surgery so I don't need to wear glasses anymore. But my eyes are a little fuzzy because they put these numbing drops and stuff in there. So we're going to print OS, Lister, and let's call it SPath. I need to make a variable here. I'm just going to use the Python folder just so I've got something to work with here that's a little interesting. And what Lister is going to do is just give you a list of everything in there. And the problem is you don't know what's a directory, what's a file, what's really going on. So now we're going to get everything split. What do I mean by split? Well we want to split this up into roots, directories, and files. Roots is very handy if you're on a Windows system on Linux. It's really not that handy because you really only have one root for Linux and everybody knows what it is. Let's call it roots, dirs, files in OS walk. Now what walk is going to do is it's going to literally walk that path, that directory structure. And it's going to determine what's a file, what's a folder, and what's a root just so you have something to work with here. So we could very easily say for, let's say, file in files, print, we're going to say file equal. So we just want to print out the files. We want to ignore the directories just for whatever reason. Name in files, yep, probably help if I spelled that right. Told you my eyes were bothering me a little bit. There we go. So there's all our files. And we could actually, you know, just do the magic of copy and paste here. We could print out the directories. So we could say the dir, all the dir and dirs. How many times are you going to say that in life? If my daughter was here, she'd be cracking up. She'd be like dir, anyways. So let's run that. And kind of whiz by real fast here, but if we scroll up, you can see there's directories in there. So there's a pi caster and, you know, there's testers and things of that nature. Now, as interesting as that is, and that's probably done incorrectly, somebody at home has probably already figured that out, we're going to actually comment this out. And I'll show you a much easier way to use the OS walk command. We're going to get only the roots. And we'll say let's call it roots equal, we're going to use the next command. We haven't really covered that. What next will do is if you're in an iterator, it will jump to the first version or the first iterator in that group. Sounds complex, but it's actually very simple. It just has a list and it jumps basically to the first position. Iterators are a little different than lists. So it's going to be a tutorial on its own. And we're going to walk our S path. And we want to get the first list that it's going to spit out there. We're going to print roots equal. And let's just not sure if that's going to print us out, right? But we're going to find out. Yeah, so there's our roots. Now the root is the root path that we're starting off with here. And through the magic of copy and paste, we're just going to very quickly go. Only the dirrs. D first. Jeez, that was bad. Only the dirrs. And we're going to get the first one. This eye searcher, I'm telling you. I had to PRK, not Lasik. So the recovery time is like months and months. I'm on one month and two weeks, I think. And I can drive and I can see. You wouldn't believe me by watching these tutorials, but I can type. But sometimes my eyes get a little weird and I got to stop and really like focus and figure out what I'm doing. It makes video gaming and coding very interesting. So as you guessed, we're getting only the directories and only the files. And we're just going to spit those out here. So you can see there's your directories in a nice neat list that you can iterate through. And there's your files that you can iterate through. And from there, you can actually, you know, get extra information like the file size using, I think, OS path and a few other things. But just wanted to make this a nice clean little tutorial on how to walk through a directory. That's all for this tutorial. If you found this educational and entertaining, be sure to visit my website, voidrealms.com, for the source code for this and other tutorials.