 Hey everybody, it's Brian, and this is our 11th Q-tutorial with C++. Today we're going to be covering the Q-Durr. Now, what is Q-Durr? If you go to the help type Q-Durr, you can just simply click it, and it'll tell you exactly what it is. It says the Q-Durr class provides access to directory structures and their contents. And you can click more, and it just jumps you down, and it gives you a very detailed reference. I want you to start using the built-in help Qt Creator. Actually, Qt comes with this very extensive help library. It's very, very good. Let's just grab that. Include, copy it, and let's go file a new project. Let's just make a new console. And we'll say Durs. And we're just going to go next, next finish. And let's just include Q-Dbug. And we're going to include Q-Durr. Now, if you're working with a new class in Qt, and you don't really know what to do, really, really use the help file. I mean, it gives you all of the functions, and if you click on a function name, it takes you right to the description. It's very, very handy. We're just going to cover some of the basic ones. For example, how to create one. Basically, the constructor right here is, you know, constant Q-Durr andurr. Reference to path, and reference to path. I mean, it's pretty simple. Really, all you need to do is just give it a name. So let's go back in here. Q-Durr. And let's give it the path. And we're going to use one of the functions called Exis. So we're going to say Q-Dbug. We just want to see if this exists. Let's run this. And you see our directory does exist. eDriveTest or whatever directory you're using. If you're on a Windows machine, you'll note that the forward slash, what Qt does automatically translates that slash into a forward slash. The reason why you don't use this slash is because that is an escape sequence. I mean, you could very easily use two of them, but it gets kind of tedious. It's just easier to use the cross-platform method forward slash. And if you're on, say, a Linux or a Unix system, you would, you know, use the forward slash method also. All right. What is another one here? Let's try a directory we know does not exist. Just type some random garbage. And let's run it again. And you can see that faults. It does not exist. Now, that's a pretty simple method of determining whether or not your directory actually exists. But how do you know what directories and what drives are actually on the hard drive? Well, that's a good question. What we're going to do is just delete that. We use the default constructor. And we're going to use drives. Now, what is drives you ask? Well, if you mouse over, it tells you it's a Q file info list. Basically, if you have any questions, like I said, jump into the help. And what's going to go up here? We're going to go down here and find it real quick. Drives, where are you at? Drives right here. It says, returns a list of root directories on the system. On Windows, this returns a Q file info objects, CDE, et cetera. On other operating system, it's just the root directory, the forward slash. See, pretty easy to use. It also tells you you can see root and see root path. And, of course, it tells you exactly what a Q file info list is if you click on it. Let's go back. Go back here and say for each Q file info. Let's actually include this. Now, if you're used to just straight C++, you're probably wondering what in the world is for each. This is a method they've actually borrowed from other languages like C-Sharp and Java. It allows you to quickly and easily go through a collection without actually doing an iterator. And let's say, oops, Q debug. And you notice how when you access this Q file info, you get all the properties of it. Well, how do you know which one you want? Very simple. You look it up in the help. For this one, we're just going to use absolute file path. Let's compile and run this. And I have quite a few drives on my system because this is my gaming slash development box. So you can see there are all my hard drives. And there would be more, but I have quite a few of them disconnected just because I didn't want them connected running up my power bill. So that's how you get the drives out of here. The QDare class also has the functionality of being able to do certain things. For example, you can create directories. You can make dir and make path. Now, what's the difference between these two? You know I'm going to tell you to look it up in the help, but I'll explain it. The make dir will make a subdirectory of the current dir where make path will actually make the folder plus all parent folders that are needed. For example, you notice how we just have mdir and there's no real reference to a path. So it's going to use the current dir in the system. But if we go make path and now it wants a constant Q string of the directory path and let's just say e test and we'll just say zzz. And let's add a little logic in here. Well, let's actually add a Q string in here just for the sake of argument here. And let's just copy and paste this. So we're just simply going to say if it doesn't exist, then we're going to create it. Let's say else. Let's get my caps lock on. Add us a little output here so we know exactly what's going on. Alright, now let's pick this apart real quick. Basically, we're making a Q dir and a Q string. The string represents the path which does not currently exist. So if it doesn't exist, it's going to actually make it with all the roots if necessary and then print out created. If it does exist, it'll print out already, misspelled. Print out already exists. Let's save and run. And you see the first time we run it, it says created. Now let's run it again. And it says already exists. Pretty neat, huh? Alright, let's go back here. And what else is there in here? You can see that there is a lot of like entry lists and things of that nature. What in the world is an entry list? Entry info list, entry list. Well, this is how you get subfolders and files out of the Q dir. For example, the entry info list returns a list of Q file infos where the entry list just returns a Q string list. So let's actually click the entry info list. And it says, excuse me, returns a list of Q file info objects for all the files and directories in the directory according to the name and absolute filters previously set with the set name filters, etc., etc. I'm not going to get so much into filters this tutorial, but I want you to really understand how to use this, because this is a very big part of using the Q dir. So let's go back here. And let's actually just get rid of that string. And we'll say, for each Q file info and item and enter entry info list. And you got some properties, but we're just going to leave it blank and I want to show you exactly what's going on here. And we will say, Q debug and item. Absolute file path. Compile and run. And you see, there is a listing of all the directories. And sure enough, there's that triple Z directory that we made earlier. And you also notice how it's got the dot and the dot dot. You can set filters, get rid of those, but that is an old Unix notation. That is, you know, the parent folder and the parent parent folder. Pretty easy to understand, but if you've never seen it before, you might be confused with what those directories are. And that's very simple. Now, if you wanted to determine what this was, you could say something to the effect of so let's back up here. If is dir, then you would say Q debug. Whoops. Let's just magically copy and paste this just to save us some typing. And we'll say file. So that would be how you would determine if it's a file or directory. You just say the Q file info. You would say is dir or is file. And it would trigger off depending on which one it was. I don't think I have any files out there, so these should all be directories. And sure enough, we run it. It says dir and then there's a bunch of them. Alrighty, well, this is Brian. I hope you found this video educational and entertaining, and thank you for watching.