• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

vbScript locate file based on first few characters

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
antonioking
Asked:
antonioking
1 Solution
 
Robberbaron (robr)Commented:
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

Open in new window

0
 
antoniokingAuthor Commented:
Thanks!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now