1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using batch file to open multiple text files using Notepad simultaneously

Discussion in 'Operating System' started by terrylau, Jul 2, 2009.

  1. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Well .. you can change the file extension here :
    Code:
    .
    .
        If Right(MyFile.Path,4) = ".txt" And Left(MyFile.Name,Len(Prefix)) = Prefix Then
    .
    .
    
    [[ You were not very clear about the requirements of your program, so I am assuming you need view html files in notepad. ]]

    So, your code would look like :
    Code:
    Dim objFSO
    Dim MyFile
    Dim MyFolder
    Dim objShell
    Dim Prefix
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set MyFolder = objFSO.GetFolder("D:\Test")
    Set objShell = WScript.CreateObject("WScript.Shell")
    
    Prefix = InputBox("(*) Enter prefix for file-names (e.g. for opening 0310*.html or 0310*.htm files, enter 0310) :"+vbcrlf+vbcrlf+"(*) Leaving this blank or, clicking cancel will open *.html or *.htm files ...", "File-Name Prefix")
    For Each MyFile In MyFolder.Files
        If (Right(MyFile.Path,4) = ".htm" Or Right(MyFile.Path,5) = ".html") And Left(MyFile.Name,Len(Prefix)) = Prefix Then
            objShell.Run("notepad " + MyFile.Path)
        End If
    Next
    If you need anything more, feel free to tell :)

    [COMMENT]Yeah, about the reward : a simple "Thank you" is enough for me :D [/COMMENT]
     
  2. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Thanks for your response. very generous. i tried the program but doesnt bring up html files.
    i thought maybe they would come in firefox or internet explorer.

    i simply want to input "ran24045.htm" and have the file come up in firefox or internet explorer or a program that reads htm not sure if notepad would do it. but the program above doesnt respond.
    i changed the folder name to the appropriate one. the previous one that you did with the text files is great except it needs to now bring up an htm file.
     
  3. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    ps. tried your instruction 2404 but no response. be great to get this working
     
  4. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    running the script reads an index file for a web page that i have it is a firefox file but notepad doesnt strip the html to make it readable. the program doesnt read the input that i put in e.g. the above comes up if i hit cancel when i input 2404 or ran24045.htm nothing happens. also coming up in notepad wont be effective and would need to be firefox or internet explorer.
    hope this gives you more to go on.
     
  5. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Code:
    Dim objFSO
    Dim MyFile
    Dim MyFolder
    Dim objShell
    Dim Prefix
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set MyFolder = objFSO.GetFolder("c:\horses\form")
    Set objShell = WScript.CreateObject("WScript.Shell")
    
    Prefix = InputBox("(*) Enter prefix for file-names (e.g. for opening 0310*.html or 0310*.htm files, enter 0310) :"+vbcrlf+vbcrlf+"(*) Leaving this blank or, clicking cancel will open *.html or *.htm files ...", "File-Name Prefix")
    For Each MyFile In MyFolder.Files
        If (Right(MyFile.Path,4) = ".htm" Or Right(MyFile.Path,5) = ".html") And Left(MyFile.Name,Len(Prefix)) = Prefix Then
            objShell.Run("notepad " + MyFile.Path)
        End If
    Next
    can you see anything wrong.
     
    Last edited by a moderator: Apr 27, 2010
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    It does !! I re-checked it. It does open .html / .htm files in NOTEPAD.
    Have you changed the path in the script ?? It was "D:\Test\".

    You should have told me that you want them to be opened in IE or FF.
    Anyway, we can modify the script.

    For opening, "ran24045.htm", you should input the prefix which in this case can be "ran" and not 2404 (which is suffix !).
    Probably that's why you thought the script is not responding, as it would have found no files with prefix 2404 !
    If you enter (let's say) "XYZ" in the dialog-box, the script displays the files : XYZ*.htm and XYZ*.html.

    Nope, nothing wrong ... but you need to modify it as follows for opening pages in FF/IE.

    For Internet Explorer ::
    Code:
    Dim objFSO
    Dim MyFile
    Dim MyFolder
    Dim objShell
    Dim Prefix
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set MyFolder = objFSO.GetFolder("c:\horses\form")
    Set objShell = WScript.CreateObject("WScript.Shell")
    
    Prefix = InputBox("(*) Enter prefix for file-names (e.g. for opening  0310*.html or 0310*.htm files, enter 0310) :"+vbcrlf+vbcrlf+"(*) Leaving  this blank or, clicking cancel will open *.html or *.htm files ...",  "File-Name Prefix")
    For Each MyFile In MyFolder.Files
        If (Right(MyFile.Path,4) = ".htm" Or Right(MyFile.Path,5) = ".html")  And Left(MyFile.Name,Len(Prefix)) = Prefix Then
             objShell.Run("iexplore " + chr(34)+MyFile.Path+chr(34))
        End If
    Next
    For Firefox ::
    Code:
    Dim objFSO
     Dim MyFile
     Dim MyFolder
     Dim objShell
     Dim Prefix
     
     Set objFSO = CreateObject("Scripting.FileSystemObject")
     Set MyFolder = objFSO.GetFolder("c:\horses\form")
     Set objShell = WScript.CreateObject("WScript.Shell")
     
     Prefix = InputBox("(*) Enter prefix for file-names (e.g. for opening  0310*.html or 0310*.htm files, enter 0310) :"+vbcrlf+vbcrlf+"(*) Leaving  this blank or, clicking cancel will open *.html or *.htm files ...",  "File-Name Prefix")
     For Each MyFile In MyFolder.Files
         If (Right(MyFile.Path,4) = ".htm" Or Right(MyFile.Path,5) = ".html")  And Left(MyFile.Name,Len(Prefix)) = Prefix Then
             objShell.Run("firefox " + chr(34)+MyFile.Path+chr(34))
         End If
     Next
    I have tested both of them before posting .. they MUST work. [:)]
     
  7. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Thank you for your time and great effort. it does work except that it only opens text files. e.g. if I save the htm file as a text file it will open but as an htm or html file it doesnt open.
    when i hit the blank or cancel it will open an index file (web index) saved as a text file and I have also saved an html file as a text file and it will open that. but does not open htm or html files.
    not sure if this is any help but maybe you can work something from it.
    regards
     
  8. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    an html file saved as "all files" will come up on the program if i press cancel. but cant call it by inputting the prefix.
     
  9. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Bit more experimenting. if the htm file is saved as all files it will call up the prefix is case sensitive. calls it up if capitals are used e.g. ALN16038 (the only one saved as all files - wont let me save any more) comes up if ALN is put in. will come up if i hit cancel but is the only htm file (saved as all files) that comes up.
    regards
     
  10. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    I **really** don't get what you are trying to tell :crazy: ..
    What does that mean ??
    Save an html file as "text" ?? With a ".txt" extension ? or what ??

    And I have tested this script (again before posting this) .. it opens ANY FILE WITH ".HTM" or ".HTML" EXTENSION, WITH THE PREFIX SPECIFIED BY USER.

    And, obviously the prefix is CaSe-SeNsItIvE.
    We have not implemented any sort of technique in the code that would Brute-Force all possible cases for a prefix and would open a file.
     
  11. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Thanks for answering. What I mean is if I open a text file with the original program you did for me and then save it as an htm file the second program will open it.
    An htm file that comes from a zipped file and saves as RAN24044.HTM wont open with the program.
    it may be the type of file e.g. it shows as a firefox file in the folder. Will do some more work on this and maybe I can stumble on the answer.
    regards
     
  12. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    Firefox Document (.HTM)file:///C:/horses/form/DOO05111.HTM


    This is the file type that wont open. it comes in a zipped file with 8 or 9 files in each zipped file. a program such as turbo browser will open it but dont know the secrets that they use to make it work.
     
  13. topsy99

    topsy99 New Member

    Joined:
    Oct 4, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    retired
    have tried the open with command (right click mouse) with the program on the above file type and it comes up "not a genuine win32 application" what does that mean.
    this may be the issue with these files. if i open with Firefox and save again as an htm file i can open with the program.
     
  14. rcurrell

    rcurrell New Member

    Joined:
    Aug 30, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I want to open 2 PowerPoint slideshows at the same time, but I need for each to appear on different monitors. Here is the code I used:

    Code:
    Dim objFSO
    Dim MyFile
    Dim MyFolder
    Dim objShell
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set MyFolder = objFSO.GetFolder("C:\LCARS")
    Set objShell = WScript.CreateObject("WScript.Shell")
    For Each MyFile In MyFolder.Files
        If Right(MyFile.Path,5) = ".ppsx" Then
            objShell.Run(MyFile.Path)
        End If
    Next
    
    Each of my slideshows are setup to play on its own monitor, but the code starts them both on the same. Do you know of a way to run PowerPoint slideshows on different monitors at the same time?

    Thanks,
    rcurrell
     
    Last edited by a moderator: Aug 31, 2012

Share This Page