SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Well .. you can change the file extension here :
Code: VB
.
.
    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: VB
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

Offtopic comment:
Yeah, about the reward : a simple "Thank you" is enough for me
topsy99 like this
topsy99's Avatar
Go4Expert Member
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.
topsy99's Avatar
Go4Expert Member
ps. tried your instruction 2404 but no response. be great to get this working
topsy99's Avatar
Go4Expert Member
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.
topsy99's Avatar
Go4Expert Member
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 shabbir; 27Apr2010 at 16:31.. Reason: Code blocks
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Quote:
Originally Posted by topsy99 View Post
Thanks for your response. very generous. i tried the program but doesnt bring up html files.
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\".

Quote:
Originally Posted by topsy99 View Post
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.
You should have told me that you want them to be opened in IE or FF.
Anyway, we can modify the script.

Quote:
Originally Posted by topsy99 View Post
ps. tried your instruction 2404 but no response. be great to get this working
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.

Quote:
Originally Posted by topsy99 View Post
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.
Nope, nothing wrong ... but you need to modify it as follows for opening pages in FF/IE.

For Internet Explorer ::
Code: VB
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: VB
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. []
topsy99's Avatar
Go4Expert Member
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
topsy99's Avatar
Go4Expert Member
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.
topsy99's Avatar
Go4Expert Member
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
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
I **really** don't get what you are trying to tell ..
Quote:
Originally Posted by topsy99
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.
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.