Batch Program Help
I have a text file stored in a location. I have to read the file and see if the file has any characters in it. If it has I had to invoke another batch file. I am struck writing this. Anyone can you help me here. For now,
you can have the batch file to do a netsend. I can make necessary changes from that part.SugeshKumar
SQL Server MVP
http://sugeshkr.blogspot.com
June 28th, 2010 1:21am
You might be getting a bit too fancy for plain old ms-dos batch.
I suggest using VBScript InStr.
Option Explicit
Dim oFSO, sFile, oFile, sText, LookingFor,CharIsInText,WshShell
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile = "file.txt"
LookingFor = "sometext"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If Trim(sText) <> "" Then
If instr(sText,LookingFor) then
CharIsInText=True
End If
End If
Loop
oFile.Close
If CharIsInText then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe"
end if
End if
This will read "file.txt" for "sometext", if it is found, it will run notepad.exe.
Free Windows Admin Tool Kit Click here and download it now
June 28th, 2010 2:54am
Hi,
You may also try the following bat file:
@echo off
for /f %%c in (text.txt) do if not %%c=="" call anotherbat.bat
Or
@echo off
for %%R in (text.txt) do if not %%~zR equ 0 call anotherbat.bat
Thanks.
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial
to other community members reading the thread.
June 28th, 2010 9:00am