vbScript locate file based on first few characters

Posted on 2014-07-11
Last Modified: 2014-07-29
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

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
    If oFile Is Nothing Then
    	MsgBox "No matching file found"
    End If

    Open in new window


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    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  ( 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 ( 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…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now