View Full Version : Looking for a better way


SQL_Hell
01-29-2008, 08:26 AM
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?

KeithG
01-29-2008, 08:44 AM
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