locked
How to read the contents of a file from batch file RRS feed

  • Question

  • Hi

    I have a text file which contains exe files.  I need to read those exe file names and then execute the same in order they occur. Sample content of the text file a.txt is as below.

    "If you are looking at previous version then use 8792xINT.EXE if you are looking for the current version then check 8793xINT.exe

    please use README.TXT file before you use any above files" 

    I need to read and execute 8793xINT.exe from above text in batch file.  Here number 8793 is variable changes as version changes but xINT.exe is constant.

    Thank you in advance

    DBC


    DBC

    • Moved by Bill_Stewart Tuesday, December 30, 2014 2:47 AM Unanswerable drive-by question
    Wednesday, December 3, 2014 12:26 PM

Answers

  • I am stuck here. even the below code is not working to extract the exe files. Need help to fix this.


    Sorry, can't fix this script because it makes no sense. As I said before, extracting the names of your .exe files is messy using a batch file. Much better to continue with a VBScript. You could, for example, split the contents of your text file into an array of words, then examine the words starting and the end of the array until you find a .exe substring. Alternatively you could use the instrrev function to locate the last .exe substring in your text data.


    • Edited by Frederik Long Thursday, December 4, 2014 11:46 PM
    • Proposed as answer by Frederik Long Friday, December 5, 2014 2:42 PM
    • Marked as answer by Just Karl Monday, April 20, 2015 5:13 PM
    Thursday, December 4, 2014 9:25 PM

All replies

  • I have a text file which contains exe files.

    When you write
    I have a text file which contains exe files
    I suspect you actually mean
    I have a text file which contains a number of exe file names.

    If so then extracting their names using a batch file is messy. Much better to use VBScript or PowerShell. I recommend you have a go at it, then post your script here and ask for assistance with the finer points.

    Wednesday, December 3, 2014 5:25 PM
  • Sorry... 

    code i use is here -

    strScriptFile = Wscript.ScriptFullName ' C:\Patch\test_download3.vbs

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strScriptFile)
    strFolder = objFSO.GetParentFolderName(objFile) 
    Set objShell = CreateObject("WScript.Shell")
    strLink = "http://dbc.download.com/patches/" 
    strSaveTo = "C:\patches"
    objShell.CurrentDirectory = strSaveTo
    objShell.Run Quotes(strFolder & "\wget.exe") & " " & Quotes(strLink) & " -N",1,True
    objShell.CurrentDirectory = strFolder
    Function Quotes(strQuotes)
    Quotes = chr(34) & strQuotes & chr(34)
    End Function

    the above code geneates index.html.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
     <HEAD>
      <TITLE>Index of /140410/patches/</TITLE>
     </HEAD>
     <BODY>
    <H1>Index of /140410/patches/</H1>
    <PRE>   <A HREF="?N=D">Name</A>                              <A HREF="?M=A">Last modified</A>        <A HREF="?S=A">Size</A>  
    <HR>
    <IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="..">Parent Directory</A>                  12-Oct-2014 16:25     1k  
    <IMG SRC="/icons/generic.gif" ALT="[FILE]"> <A HREF="8792KB.exe">8792KB.exe</A>                      18-Oct-2014 1:19  6.4M  
    <IMG SRC="/icons/generic.gif" ALT="[FILE]"> <A HREF="8793KB.exe">8793KB.exe</A>                      18-Oct-2014 2:19  4.2M  
    <IMG SRC="/icons/dir.gif" ALT="[FILE]"> <A HREF="2834KB.exe">2834KB.exe</A>                      20-Oct-2014 16:18  2.5M  
    <IMG SRC="/icons/dir.gif" ALT="[DIR]"> <A HREF="extra/">extra/</A>                            17-Sep-2013 23:09     1k  
    <IMG SRC="/icons/generic.gif" ALT="[FILE]"> <A HREF="readme.txt">readme.txt</A>                        30-Jan-2012 11:54    20k  
    </PRE><HR>
    </BODY></HTML>

    From above generated index file and re run the above script to in loop to download the exe files in c:\patches and deploy the same with schedule task on the PC in our Isolated ODC. Number of exe files this time only 3 exe.  I am using counter to loop the down load. 





    • Edited by D-B-C Thursday, December 4, 2014 6:33 AM
    Thursday, December 4, 2014 6:26 AM
  • The code you posted might generate your text file. You now need to develop it further to extract the names of the .exe files.
    Thursday, December 4, 2014 8:22 AM
  • Yes.  I am stuck here. even the below code is not working to extract the exe files.

    SET n = 1
    SET F-Name=index.html
    for /f "tokens=3 delims= " %%a in ('find /N "[FILE]" C:\patches\%F-Name%') do set PCH=%%a
    %a%
    pause
    %PCH%
    pause
    set /a ee=%PCH%-112
    more +%ee% c:\patches\%F-Name% >> findtext.txt
    findstr "[FILE]" findtext.txt >>DATN.txt

    Need help to fix this.  Thank you


    DBC

    Thursday, December 4, 2014 7:39 PM
  • I am stuck here. even the below code is not working to extract the exe files. Need help to fix this.


    Sorry, can't fix this script because it makes no sense. As I said before, extracting the names of your .exe files is messy using a batch file. Much better to continue with a VBScript. You could, for example, split the contents of your text file into an array of words, then examine the words starting and the end of the array until you find a .exe substring. Alternatively you could use the instrrev function to locate the last .exe substring in your text data.


    • Edited by Frederik Long Thursday, December 4, 2014 11:46 PM
    • Proposed as answer by Frederik Long Friday, December 5, 2014 2:42 PM
    • Marked as answer by Just Karl Monday, April 20, 2015 5:13 PM
    Thursday, December 4, 2014 9:25 PM
  • Hi Frederik,  Thank you I got what you said.  Yes i can do it using instrrev function.

    DBC

    Friday, December 5, 2014 1:10 PM