Hey guys, Master Jake here again today. And now, I’m going to be showing you how to read from a text file or other file you know. Watch my writing to files video first if you want to learn how to write and read the files. This is just going to be a basic example that basically just loads up the contents of a text file and prints them out.
So, first we’re going to open up a notepad and we’re going to type Dear User. I’m going to go down a couple of lines, tab out. I’m going to say, “This is a very basic example of a batch file that reads the contents of a text file and echoes it out into the console window.” I’m going to tab over twice, sincerely, Some Guy. Now, we’re going to save this text file as just a test.txt. Just click Save.
And now we’re going to open up a basic batch file and we’re just going to have an echo off. Now, the cool thing about this command is it automatically writes the contents out. You don’t have to echo the statement off, it automatically does it for you. I’ll be using the find string command today, findstr, find string. Now, you can learn more about this command by going to start cmd, or start run, type cmd, then type find str, forward slash, question mark and then it will teach all of it. So, you can watch my—commands video and you could learn more about this. I’m just going to teach you the basic thing that I use most of the time. So, use find string and then we’re going to type the string that we want to find inside the file and it’s going to—if it matches it, it will pull it up and print it back up.
So, what were’ going to do to you know screw around with this is we’re going to put the forward /v command and basically that’s going to find every line that doesn’t conation a match of the string that you type. So, when you put the /v in there, now you’re going to put the string in double quotes. So, if you’re trying to find and print all the file, all the contents that you don’t want to read then make suer if you’re trying to print the whole thing out, make sure you type in something that’s not in the file. Like for example—we don’t put any word characters like semicolon in there. I’m sure that it never appears in the text file. Actually, we know it doesn’t. So, I’ll put that in there and then we put the file, justatest.txt, so I’m going to run it, oh yeah we need to put a pause, greater than, nul statement. I’m going to save this as readfromfile.bat. Make sure .bat is on the end. Change Save as type to All Files and click save. And I’m going to run this new file, double click it And you will notice in the batch window, it has echo it out all the contents of that text file that we just wrote a second ago then it’s pausing and request key in—
So, this is just my way. I’m sure there’s tons of ways to do this bu this is just my way of echoing out all the contents of a file. Basically, by using the command /v which is going to echo everything that’s not this so it’s going to search for this. And it’s going to—every line it goes down in the file if it doesn’t contain this text, then it’s going to echo that line off. If it does contain, it’s going to skip it.
So, let’s go into our justatest thing, appear at the top, we’re going to type file created on let’s see what’s today Saturday September 13th 2008. So, that’s just going to be a reference. We’re going to save that in there. Now, under the string, we’re just going to simply type file created on and then we’re going to save it and then read from and it’s still not—it’s not going to output the text right there because it went through and it found that string in the document. And it found it so it did not you know type it out because we have the /v command. So, if you have like some text in there that you don’t want to be typed out, just include it in the quotations. But if you want everything to be read then make sure you put something read domain here and just to keep numbers and letters in there though. You don’t want to put in special characters and screw around the best file.
So, this has been the basic tutorial. This is just my way of doing it. There’s so many, I’m sure. Research it if you want. Thanks for watching my videos. See you guys again soon.
Transcription by:
Scribe4you Transcription Services