Placeholder Image

字幕表 動画を再生する

  • all right, Mike Odors and Cody's Welcome back to another very exciting video.

  • And I'm so excited about this one because it's essentially the O.

  • C.

  • D organizer's dreams.

  • It just ticks all the boxes from making a really awesome coding challenge And what we're gonna build us a Python script that's gonna help keep our desktops completely clutter free.

  • So essentially, what we're gonna do is we're gonna automate the desktop cleanup.

  • So yeah, I guess that's pretty much it for the intro.

  • So let's get started.

  • All right, So what?

  • I'm thinking that we're going to start with this just to kind of write down the requirements for this build, basically.

  • So try to figure out what we need to get done.

  • What we need the program to be able to d'oh.

  • And then we'll get into actually building out each separate thing s.

  • So I'm gonna start with that.

  • All right, so these are the requirements that I've come up with.

  • It needs to track the desktop.

  • We've done this before.

  • In other videos, if you look at my video called Super Quick Python Automation Ideas, one of the ideas in that video was to move files between different folders And I suggested that you could use this to clean up your downloads holder so that you automatically assume it's something get gets put into the downloads folder.

  • You just move it into where you want it to be.

  • This is basically what we're going to do now, but for the desktop.

  • So I'm probably going to just copy that pretty much.

  • And since I didn't go through kind of what everything waas in that video and how it works, I'm just gonna copy that and go through actually in, say, like, what the different parts do and why I used two different things, and then we wanted to move files into that folder we wanted to run in the background.

  • So that's something that some of you have been asking for us.

  • Well, is how to actually make a python script Iran constantly in the background.

  • So you don't have to, like, run it manually every time you wanted to run.

  • So we're going to go into that and actually do that properly.

  • Oh, auras properly as I can do it, okay.

  • And then system for file organization.

  • We need to basically create some sort of system for actually organizing the different files.

  • And then we need to find all the different file types, basically.

  • So I need to just go rule to see what file types there are because we want Thio essentially be able to track all different file types.

  • But we're also gonna add a safety net so that if there's a file that we haven't got in our list, then we'll get added to like a folder called Categorizes Him Like that.

  • So now I think what I want to do is try to come up with a system for file organization, basically this I think it's going to be the main part of the build, like figuring out how to actually organize the different things.

  • And then this is just gonna be a short explanation of how I make this wrong in the background.

  • All right, so I'm gonna get into just creating the system for final organization, and I'm just gonna make this up as best as I can.

  • Hopefully, it'll be good.

  • All right.

  • So I think I think I've come up with the system, which was kind of what what I was thinking before, as well.

  • And essentially we're gonna create folders for each file type category.

  • So images, video, audio text, etcetera is gonna be a couple different ones.

  • I can probably can't capture a ll the different types.

  • Um, but yeah, something like that.

  • And then within each folders within the images folder, we might have either separate like Francis images.

  • There are several different types of images that you can download like there's pain J and J.

  • Peg.

  • And there's a couple other ones I don't remember right now, but there are a couple of the ones, and then within these folders, we're gonna have sub folders that are going to be structured by the dates.

  • So the first sub folder is gonna be the year so 2019.

  • So all the files that get out in 2019 get added into 2019 folder and then within that, we're gonna have all the different months, so folders for each month and then the file gets added to the corresponding month to when it was added, and then within the month folder, we're gonna have either a sub folder called Days.

  • So we're gonna have, like, day, one day, two etcetera, or we're just gonna have the files.

  • I'm not sure which one is gonna be the best.

  • Because, like I said before, we we want to go into detail.

  • But we don't want to go into too much detail, because then it kind of gets over complicated.

  • Andi, I think that at least for me, I don't add that much stuff to my desktop on a daily basis that it would end up being like a huge folder for one month.

  • What you could do is you could probably divide it into maybe weeks.

  • I think that would make more sense.

  • But for now, we're just gonna keep it at us.

  • All the files are gonna be added into the month folder.

  • That's gonna be our structure.

  • And, uh, now, let's get to actually building this thing out.

  • So, uh, we're gonna start by just like I said, copying and pasting the code from the previous one that I built, and then I'm gonna go through and explain kind of what it does.

  • All right, so now we've actually I did have some problems trying to figure how to actually make this work again.

  • But now it seems to be working, and basically I've created a folder called Cow Here on my Desktop.

  • So we run it.

  • So right now it's running.

  • It's checking the desktop to see whether we've put and you file there so we can just create a new file.

  • Let's cool it.

  • Hello, doc.

  • Text And what it should do with you should I don't know if you can.

  • You'll see this, actually.

  • Wait, Let's move my head away for now.

  • All right?

  • But right now we're creating a new text file, like, so you can see it gets added and then gets removed.

  • And as you can see, it ends up here.

  • Hello?

  • Don't text.

  • And if we create another one gets added again.

  • Thio?

  • Yep.

  • So here you go.

  • Hello, Doc.

  • Takes to So we just added another number two.

  • What if there's another file already existing with same name?

  • So that means that we won't get the problem of, like, duplicates.

  • It will still work, Although I guess that might be a problem that it says hello dot text, too.

  • Uh, let's see what happens if we add an image or something.

  • Let's go to recent ce And let's, uh, this image back going live, right?

  • So now, as you can see, this right here, this one has the same name as this one.

  • And if we move that out into the desktop Okay, so this is a problem?

  • Because right now, it just depends the number to the end of the file.

  • And that means that we we basically changed the file type from being a J peg, too.

  • Ah, j pig To which is not actually following.

  • So that's something that we need to fix.

  • We need to make sure that it doesn't depend the number to the file type.

  • It should only upend the number to the name.

  • Okay, so that's something that we need to fix.

  • So I'll do that right now, and then we'll go through how this whole script kind of works.

  • Okay, so now I think it works.

  • Um, I made it so that it should renamed the files and not changed the extension.

  • So basically, we're gonna take this image P and G move that here so that just since we don't have another image or another file name that name, it just adds it as it is.

  • And now we're going to do is we're gonna add the same file again with the same exact name and what it should dio is it should do post tudo PNG.

  • So basically no renames the first part of the of the file name and keeps the extension the same s so we're not actually modifying what filed type it is.

  • Which is good.

  • All right, let me try to explain this, especially I can.

  • So, essentially, what we have is this this is watchdog.

  • It's a library that I use.

  • And, ah, what that does is essentially tracks.

  • It does a lot of things, but what I use it for is for tracking folders.

  • Okay, So essentially, what we're doing right now is we're tracking the desktop that the path to the desktop as a folder and then this watchdog basically has something called file system event temblor, which has a sub method which is called unmodified, and that basically tracks.

  • So anytime something happens, an event happens.

  • We add a new file of something to the desktop.

  • It triggers this method that runs.

  • So basically what we do then is we just run through this directory, which is the death stop folder, and we just check all the files in that folder to see if any new files have been added.

  • So we check all the files and we make sure that we're not changing the actual folders that we're not trying to put the folder within itself.

  • And then what we do is we shake what the final name is.

  • And if it's not cow, then we can go ahead and try toe.

  • Either move it into the folder or rename it.

  • So what we want to do is we want to check whether our folder already contains another file named the exact same thing.

  • And if it does, then we wantto I just basically added an eye variable that we just increment for.

  • Each file that already exists says you can see here we already have a file named Post a PNG.

  • So what we do then is we increment that I buy one.

  • So we then creates post to dock PNG.

  • And then if we add another one called post a PNG, it'll be called post three dot PNG and so on.

  • I feel like this didn't really make sense when I explained it, but I think I think you understand.

  • So that means that we've added a safety net so that we don't accidentally replace any files, which can be a problem.

  • Because if we had two files with the same name than it might automatically replace that file or delete it or do something weird and then what we use is a west dot rename and that basically needs the path to the original file and then the path to the new place where you want to put the file.

  • So this is the path to where the original file iss and then you also add the file name, and this now becomes the path to where we want to put the file.

  • So folder destination, which is this folder.

  • And then we also add the new name of that file, which is going to be whatever we come up with the name to be.

  • So that's how that works.

  • What we need to do now is we need to creates a system for actually organizing this far these files and we already have that system in here mapped out for us.

  • So now the next step is gonna be basically to creates.

  • I think I'll think I'll manually create the folders that I wantto like have us the main categories.

  • So images, video, audio text because I don't think it makes sense.

  • Right now, Thio have the program do that by itself.

  • But then within these folders, we're gonna have sub folders.

  • So they're going to be the year month, and then all the files, and that's gonna be created automatically.

  • So we're gonna automate that process.

  • But the main categories, I think it makes sense to just do them on my own based on the most common file types that I use.

  • So first, we're gonna try to just figure out what are the most common file types.

  • And based on that, I'm gonna create the different folders.

  • And then we're going to create, like, a bunch of different cases for all the different file types, and that shouldn't sort them into the right folders automatically.

  • So that's the next step finding out what are the different file types?

  • Okay, so I think this is a good place to take a break.

  • I decided to divide this video up into a part one and part two, and there's a link in the description to part two of this video where we finished the script off and you don't wanna miss it.

  • It really turns out great.

  • So go watch it.

  • Also, before you go, I'll be getting back into my streaming on twitch starting on Monday.

  • So every Monday, Tuesday and Wednesday between 2 p.m. And three PM Central European time, I'll be like coding stuff on Twitch.

  • And also since I did a community posted on YouTube asking what you guys think I should do more videos on.

  • And a lot of you guys are asking for more flutter and more python, and you also wanted to see me build something from start to finish.

  • I decided that on Monday streams, I would be starting a new series called Building An Act from Scratch.

  • And in this series, I will be essentially building an app from scratch using flutter and python.

  • And this video will also get uploaded to YouTube every to stay at 3 p.m. So either you can join me live on Mondays at two PM on twitch, where you can watch it back on cheer stays when I uploaded it to YouTube and what we're gonna do in this series is literally go from an idea to finish after, and it's gonna be really exciting stuff we're gonna go through after sign front and back and rest AP eyes.

  • It's gonna be full on, so don't miss it.

  • But anyway, that's it for this one.

  • I hope I'll see you in the next one.

all right, Mike Odors and Cody's Welcome back to another very exciting video.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

Pythonの自動化プロジェクト。デスクトップの自動クリーンアップ(その1) (Python Automation Projects: Automatic desktop cleanup (Part 1))

  • 1 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語