How to Write File Contents to Screen
Keywords: display
Question:
I use a file I named, ExtractLines.WBT, to search for strings in my database and write the lines found to a new file. I then view the new file in Notepad. The program works fine and serves me well.Is there a way to write the lines directly to the screen from within the winbatch file? Or write to the clipboard or a temporary file and then show on screen directly from the WinBatch program?
Answer:
There are many ways to do what you want. Here are some notes:Here is a file and a binary example:
- For the easiest, with minimal change to your program, use the AskFileText function to display the data. Add the following line to the end of your script...
AskFileText("Matching Lines",target,@unsorted,@single)You can resize the outside dimensions of the AskFileText with the WinPlace function, but there is no way to increase the inside dimensions of the width of the file contents display box. You can change the font used in the box with the IntControl(28,,1,0,0,0) function.
- You could use the BoxOpen and BoxText commands to display it on the screen as you go. See the WinBatch manual (the small one) or the WinBatch.hlp file for info on the Box commands.
- Using binary operations instead of the File operations would make it faster.
- On a slightly different topic, you could investigate our "Searcher" extender which can do rapid searches of entire hard drives for data in files. But it does not show you the line with the data on it.
- You may wish to use "AskFileName" at the top of your script to help you locate the file instead of your three askxxx boxes.
;display the contents of a file testfile1=FileLocate("win.ini") old = FileOpen(testfile1, "READ") msg="" while @TRUE ; Loop till break do us end line=fileread(old) If Line == "*EOF*" Then Break msg=strcat(msg,line,@CRLF) endwhile FileClose(old) display(5,"Filetext" ,msg) ;Binary example (runs much faster) fs=FileSize("C:\WINDOWS\WIN.INI") binbuf = BinaryAlloc(fs+100) if binbuf == 0 Message("Error", "BinaryAlloc Failed") else BinaryRead(binbuf, "C:\WINDOWS\WIN.INI") maxlen=min(binaryEODget(binbuf),30000) text=Binarypeekstr(binbuf,0,maxlen) binbuf=BinaryFree(binbuf) endif display(5, "", text)
Article ID: W13231Filename: Display - Write File Contents to Screen.txt