Looking for a better way

SQL_Hell

SQL Server DBA
Local time
Today, 23:31
Joined
Dec 4, 2003
Messages
1,361
Hey all,

I am writing a DTS package to process a number of excel files and I need some help with the VBscript part of it.

I want to take parts of the file name to use in a variable, the files names look like this:

x_Choc_1999_0106.csv
x_Cocoa_2007_0112.csv

I am only interested in whether its Choc or Cocoa, so I have the following code to achieve the required result:

FOR each fil in fold.Files

file = strReverse(fil.name)
file = MID (file,Instr(file,"_")+1)
file = mid (file,Instr(file,"_")+1)
file = strReverse(file)
file = mid (file,Instr(file,"_")+1)
'msgbox "" & file


This code works ok but it just doesn't seem very nicely coded, a bit clunky.
Is there a better way I can achieve this?
 
You could just use the left function to test the name

if Left(FileName,6)="x_Choc" then
.....
Else if Left(fileName,7)"x_Cocoa" then
....
End if
 

Users who are viewing this thread

Back
Top Bottom