Of course you can.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = objFSO.GetFolder("C:\Test")
Set objShell = WScript.CreateObject("WScript.Shell")
For Each MyFile In MyFolder.Files
If Right(MyFile.Path,4) = ".txt" And Left(MyFile.Name,4) = "0310" Then
objShell.Run("notepad " + MyFile.Path)
In VB (and VBS), you use the Right, Left and Mid functions to extract sub-strings of specific lengths from specific positions in a string.
So, what I basically do is; I check the last 4 characters of the file-path with
. If it matches with ".txt", I open the file.
Your question was to open 0310*.txt.
How I modified the code is : I kept the previous check for txt extension + I added one more condition, where I check if the first 4 characters of the file-name (NOT
file-path) is 0310.
I hope this made the point clear. Here are some further examples :
CRITERIA .......... CONDITION
.......... Right(MyFile.Path,4) = ".txt"
.......... Right(MyFile.Path,4) = ".txt" And Left(MyFile.Name,4)="0310"
.......... Right(MyFile.Path,4) = ".txt" And Left(Right(MyFile.Path,6),2) = "A"