Solved

# vbScript locate file based on first few characters

Posted on 2014-07-11
217 Views
I'm developing a script that will attach a number of files to an email and send the email.

Could somebody help me with the correct code that can locate a file within a folder that begins "01012014"
These first 8 characters will be unique

Thanks
0
Question by:antonioking

LVL 32

Accepted Solution

try this to start
dim objShell, objFSO
Dim myFolderPath, myFilePrefix
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

myFolderPath = "C:\ee"
myFilePrefix = "01012104": iLPrefix = Len(myFilePrefix)

Set oFolder = objFSO.GetFolder(myFolderPath)
Set oFiles = oFolder.Files()
Dim oFile
For Each oF In oFolder.Files()
If Left(oF.Name,myFilePrefix) = myFilePrefix Then
'  //found the file
Set oFile = oF
Exit For
End If
Next

If oFile Is Nothing Then
MsgBox "No matching file found"

End If

0

Author Closing Comment

Thanks!
0

## Featured Post

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…