From: Aslan on
I need to parse file names and compare to a database. The file names are
delimited by an underscore "_" i.e. bobsmith_datetime.txt. I need to capture
everything before the underscore.
From: LikeToCode on
I would use the Instr Function and search for the first occurrence of the
"_". Then use that number and the Left Function to return the filename.

http://msdn.microsoft.com/en-us/library/wybb344c(VS.85).aspx

http://msdn.microsoft.com/en-us/library/sk3xcs8k(VS.85).aspx

From: Tom Lavedas on
On Mar 29, 4:31 pm, Aslan <As...(a)discussions.microsoft.com> wrote:
> I need to parse file names and compare to a database. The file names are
> delimited by an underscore "_" i.e. bobsmith_datetime.txt. I need to capture
> everything before the underscore.

I use the Split() function for things like this ...

sFN = bobsmith_datetime.txt
sFirstPart = split(sFN, "_")(0)
_____________________
Tom Lavedas
From: Reventlov on
Il giorno Mon, 29 Mar 2010 13:31:03 -0700, =?Utf-8?B?QXNsYW4=?=
<Aslan(a)discussions.microsoft.com> ha scritto:
>I need to parse file names and compare to a database. The file names are
>delimited by an underscore "_" i.e. bobsmith_datetime.txt. I need to capture
>everything before the underscore.


not tested:

LIST=CAPTUREDOS("DIR c:\data\ /S/B",TRUE)
A=SPLIT (LIST)
for i=0 to ubound(a)
text=leftof (a(i),"_")
if text<>"" then wscript.echo text
next


Function LeftOf( sText, sItem )
Dim nPos
Dim sResult
sResult = sText
nPos = InStr( sText, sItem )
If nPos >0 Then
sResult = Left( sText, nPos -1 )
End If
LeftOf = sResult
End Function

Function CaptureDOS( sCommand, bSynch )
Dim sFolder
Dim sName
Dim sTempFile
Dim sResult

sResult = vbNullString
Q=CHR(34)
sFolder = oFSO.GetSpecialFolder( TEMPORARY_FOLDER )
sName = oFSO.GetTempName
sTempFile = oFSO.BuildPath( sFolder, sName )
oShell.Run sCommand & " > " & Q & sTempFile & Q, 0, bSynch
sResult = ReadFile( sTempFile )
oFSO.DeleteFile( sTempFile )
CaptureDOS = sResult
End Function

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--