View Single Post
~ Б0ЯИ Τ0 С0δЭ ~
5Oct2009,19:32  
SaswatPadhi's Avatar
Of course you can.

Code: VB
Dim objFSO
Dim MyFile
Dim MyFolder
Dim objShell

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)
    End If
Next

Explanation :
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 Right(MyFile.Path,4). 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
*.txt%%|%.......... Right(MyFile.Path,4) = ".txt"
0310*.txt |.......... Right(MyFile.Path,4) = ".txt" And Left(MyFile.Name,4)="0310"
*A?.txt |$$.......... Right(MyFile.Path,4) = ".txt" And Left(Right(MyFile.Path,6),2) = "A"