Bill Rosener: Hello! This is Dr. Bell. Welcome back in this video. You're going to learn about task automation. Anytime. You're maintaining a website. You're going to probably find you've got lots of images, lots of HTML files. And inevitably you're going to want to make some changes. You're going to want to rename some of these files, maybe the images, or maybe make changes within the HTML files. And any way that you can automate that is going to be a lot of time saved. And I'm going to probably guess of all the videos in here, this one might be one of the most important ones.
Bill Rosener: And even if you forget some of this, just remember that there is ways to automate almost anything, we're going to go ahead and start with renaming some images. But if you, before I forget, let me press on the assignment 8 folder, and if you want to work with these same images, here's a bowls you could just save all these. And I've also created a little dummy website here with some files. And here is, for example, this is a file 3 within that website there.
Bill Rosener: Okay, let's go ahead and get started. So anyway, the very 1st step we're going to do here is I've already saved these images to my desktop in a folder called Temp. We'll go ahead and start with bowls.
Bill Rosener: Let's assume we've got in this case. We've got 10 bowls, but we could have a thousand bowls or a thousand images, and we want to rename those. So what I'm going to do is use Powershell to assist with that. And here is a Powershell you're going to find. It is installed on every Nsu computer. And it's also open source so you could download it yourself. So the very 1st step I want to do is come here. I'm in desktop temp bowls. I'm going to right. Click! That's a right click. Copy the address.
Bill Rosener: Then I'm gonna come right up here. I'm gonna type CD, and I'm gonna paste.
Bill Rosener: And if I do a dir, I'm going to get a directory listing of those files and let me go ahead and bring this over here into the screen recording. This is the very 1st command I'm going to be doing is we are going to be looking for all files, all Jpeg files, and for each one we're going to be replacing the word ball with wooden ball. So let me go ahead and copy that.
Bill Rosener: Maybe I'll drag this off, or maybe I'll just minimize that. I'm gonna come right back here.
Bill Rosener: I'm gonna position my cursor. There, I'm gonna paste, and then I'm gonna hit. Enter.
Bill Rosener: Then I'm gonna type A, DIR, and I can see
Bill Rosener: all of the bowl. All the images. Now start off with wooden. So even if I came over here, I can see the same thing there. It has renamed all those images just like that.
Bill Rosener: Okay, well, let's go ahead. And now we'll go the other direction. Let's assume we had all these files that were called. So you can see, for all Jpeg files for each one. I'm going to replace wooden ball with just ball. So let me go ahead and grab that
Bill Rosener: copy that minimize. Come back to my powershell and paste and hit Dir.
Bill Rosener: and sure enough, it has removed the word wooden dash in front of all those. So I came back even over here. Same thing here.
Bill Rosener: Okay, now, let's go ahead and let's assume we've got some documents. I'll just go ahead and open up. Say, file 3.
Bill Rosener: And in this particular case let's go ahead and assume we've got, you know, and we can even recursively go through this. So that's why I actually created a folder here, and maybe I'll open up. Say, file 6.
Bill Rosener: So here was File 3. Here is file 6.
Bill Rosener: Okay. Now, what I'm gonna do is I'm gonna come here. Well, 1st of all, let me come here to
Bill Rosener: Start off with this here directory desktop temp website. I'm going to copy the address.
Bill Rosener: Come here into Powershell.
Bill Rosener: We're gonna type. CD, I'm gonna hit paste.
Bill Rosener: And if I want, I can do a directory listing.
Bill Rosener: and I can see there's a folder in there that contains more files. But then I've got these 3 files here.
Bill Rosener: Okay, so now, what we're gonna do is if I take a look if I came back here. So all these files are, I think, identical only the phone in theirs. But whether I'm in file 3 or in file 6
Bill Rosener: right here. It's got your name and let's go ahead. And
Bill Rosener: I'm gonna minimize that here momentarily. Get back here to
Bill Rosener: I'm going to go ahead and search for your name.
Bill Rosener: I'm going to replace it with my name, and here's probably one little thing to make sure to look at, for I'm working on the desktop and a folder called Temp. And then it's called website. I'm only going to be looking for HTML files. So we're going to be doing this recursively, going through folders, subfolders, etc, there. And we're going to be. Here's what we're searching for your name. And then we're gonna do a replacement.
Bill Rosener: replacing it with Bill Rosener. So I'm simply grab this code right here.
Bill Rosener: I'm gonna copy it.
Bill Rosener: I'm right back over here. I'm going to paste
Bill Rosener: and hit enter, and just like that, you know, it went through it so quickly.
Bill Rosener: Okay, now, come back to my browser, and I'll hit a refresh, sure enough that, says Bill Rosener, and come over here and Bill Rosener. Okay, now let's go back the other direction.
Bill Rosener: So now I'm gonna replace where it, said Bill Rosener with your name
Bill Rosener: again. Make sure you specify the correct base directory. And then it's going to simply do a search and replace.
Bill Rosener: So I'm gonna simply copy that
Bill Rosener: minimize. Come back to my Powershell and paste.
Bill Rosener: and I'll come right back over here and hit refresh. And sure enough, it's back to your name. Okay, there's another way. You can even do this. And this is gonna be
Bill Rosener: Okay. So take a look right here.
Bill Rosener: Actually, I need to reverse these. It's got Nsu and I'm gonna so I'm gonna search for an issue, and I'll be walking through the code here in a moment. Let's go ahead and see this thing in action.
Bill Rosener: Okay, so I'm going to be looking in the desktop and attempt directory called website.
Bill Rosener: I need to momentarily, because what's going to happen is I'm going to take each one of these files. I'm going to search for an issue, replace it with Northeastern State University. So I create a temporary file, and then I turn around and write it back to the original file. So let's go ahead and see what happens here. I'm going to hit recursively recursive string, replacement
Bill Rosener: finish, converting files.
Bill Rosener: I'm going to come over here. I'm going to hit refresh. And sure enough, it has changed that from Nsu to Northeastern State University. Okay, let's go ahead and take a look at this. This was a much more complicated approach, but you should have access to Microsoft. Excel. So go ahead and take a look here at the code. So here is the developer Tab.
Bill Rosener: and to get your developer Tab, you'd have to come up here to file more options.
Bill Rosener: customize ribbon. And then here's your developer type. Any ventures is currently not displayed.
Bill Rosener: So then I've created a command button and let's go ahead and take a look at. So anyway, this will toggle back and forth if I press it now, it executes the code.
Bill Rosener: But if I press the design mode. Now it shows me the code, and this is quite a bit of code here. But what's going to happen is we're going to take a look.
Bill Rosener: Here is row one column 2. So I'm gonna take a look at row one column 2. That's where I'm gonna be starting.
Bill Rosener: And then I'm going to be calling, get files on all of the files in this
Bill Rosener: folder, and when I'm actually finished I've got a message box that says, finish converting files.
Bill Rosener: and I'll get you the code so you can get a little bit larger version here. So the bottom line, though, is, I'm going to be looking for
Bill Rosener: all the files. If I take a look here, we had like file one dot HTML, file 3.
Bill Rosener: So I'm going to be looking at all the files, and if the last 5 characters are dot. HTML, then I'm going to go ahead and do a string substitution.
Bill Rosener: and I'm going to take what's in cells 4, 2,
Bill Rosener: and actually let me come back here.
Bill Rosener: here is cells 4, 2. And this is going to be cells 5, 2.
Bill Rosener: So I'm going to take what's in Cells 4, 2, and replace it with Watson cells 5, 2. So I'm going to go through all the files repeating that.
Bill Rosener: And then what I need to do is
Bill Rosener: So I've written that all that information to a temporary file. And now what I'd need to do is reverse that, and take what was in the temporary file and write it back out to the original file.
Bill Rosener: And so once I've done all that, then I have a little message that says, finish converting files. So anyway, I can do that one more time here, it said Northeastern States University.
Bill Rosener: I could go ahead and replace that.
Bill Rosener: And now I'm gonna search for Northeastern States university name. And I'm going to replace that with an suo.
Bill Rosener: Okay? And I'm gonna do my recursive string replacement.
Bill Rosener: Actually, I press up here to exit the design, mode and finish converting.
Bill Rosener: Come back over here, hit, refresh, and sure enough, it has converted that.
Bill Rosener: and we come right back here. So hopefully, in this video, you learned a little bit about task automation. The 1st case, we simply renamed a file
Bill Rosener: in the second case I used power script to a search and replace. I was searching for your name, replacing it with Bill Rosenorm, and then the final, the last one we were using Microsoft excel. And there's numerous other applications that can assist assist you with some of these automations. But hopefully, in this video you learned a little bit about how simple it is to maybe change the file name on hundreds of files all at once, or to do a search and replace.
Bill Rosener: not just on one file, but on all the files. And even in that case I was going recursively through subfolders. Anyway, I'll catch you next. Video, thanks a lot. Bye.