Question Search for filename

david84

Member
Joined
May 6, 2010
Messages
20
Programming Experience
Beginner
So I'm making an update system and it writes the Application.ExecutablePath to a txt document before downloading the update. The new update that is downloaded reads that file and then deletes it. However, before deleting the file, the task must be ended. To do this, I somehow need to search within this txt document to find everything after the last \ and before the .exe. i have no idea on how to go about this, can anybody enlighten me?
Sorry if I was unclear, please ask anything you do not understood.
 
Hi there,

I think this is what you are after... (from the msdn website)

How to wait for a shelled application to finish by using Visual Basic 2005 or Visual Basic .NET

It is code to call a shelled application (i.e. Notepad, Excel, etc.) and then wait for that application to finish or close before continuing with the VB code.

I have used this successfully in projects before.

In answer to your "To do this, I somehow need to search within this txt document to find everything after the last \ and before the .exe"

This sounds like you are trying to get the filename without the filepath or the file extension.

Something like this might help you.....
VB.NET:
    Dim intPosn  As Integer
    Dim intCount As Integer
    Dim strFPath As String
    Dim strFName As String
    Dim strNAME  As String
    
    strFPath = "C:\temp\test.txt"
    
    'This finds the last "\" in strFPath
    intPosn = 0
    For intCount = 1 To Len(strFPath)
        If (Mid(strFPath, intCount, 1) = "\") Then intPosn = intCount
    Next intCount

    'strip filename from path
    strFPath = Right(strFPath, Len(strFPath) - intPosn)

    'strip extension from strFName
    intPosn = InStr(strFPath, ".")
        If intPosn <> 0 Then
            strFName = Left(strFPath, intPosn - 1)
        End If
        
    strName = strFName
 
Last edited:
wow thanks a lot. this is perfect.
however, i'm getting the following errors, is that because of missing imports?
also, to display the stripped file name in a textbox, it would be "TextBox1.Text = strNAME", right?

Errors:
VB.NET:
Error	1	'Public ReadOnly Property Right() As Integer' has no parameters and its return type cannot be indexed.	C:\Documents and Settings\f\My Documents\Visual Studio 2008\Projects\update\update\Form1.vb	24	24	update
VB.NET:
Error	2	Type character '$' does not match declared data type 'Integer'.	C:\Documents and Settings\f\My Documents\Visual Studio 2008\Projects\update\update\Form1.vb	24	24	update
VB.NET:
Error	3	'Public Property Left() As Integer' has no parameters and its return type cannot be indexed.	C:\Documents and Settings\f\My Documents\Visual Studio 2008\Projects\update\update\Form1.vb	29	28	update
VB.NET:
Error	4	Type character '$' does not match declared data type 'Integer'.	C:\Documents and Settings\f\My Documents\Visual Studio 2008\Projects\update\update\Form1.vb	29	28	update
 
David 84,

The code I originally posted was from another application (Microstation Basic), which uses dollar symbols after the string parameters.

I have modified the pervious post code and removed the dollar symbols.

Does this resolve your errors? If not, try using "Microsoft.VisualBasic.Right" instead of just Right, left etc..... The problem may be that you have a 'Left' or 'Right' property on your form (if you are using one).

VB.NET:
    'This finds the last "\" in strFPath
    intPosn = 0
    For intCount = 1 To Len(strFPath)
        If (Microsoft.VisualBasic.Mid(strFPath, intCount, 1) = "\") Then intPosn = intCount
    Next intCount
Hope this helps...
 
David 84,

The code I originally posted was from another application (Microstation Basic), which uses dollar symbols after the string parameters.

I have modified the pervious post code and removed the dollar symbols.

Does this resolve your errors? If not, try using "Microsoft.VisualBasic.Right" instead of just Right, left etc..... The problem may be that you have a 'Left' or 'Right' property on your form (if you are using one).

VB.NET:
    'This finds the last "\" in strFPath
    intPosn = 0
    For intCount = 1 To Len(strFPath)
        If (Microsoft.VisualBasic.Mid(strFPath, intCount, 1) = "\") Then intPosn = intCount
    Next intCount
Hope this helps...

Yup. Works like a charm ;) thanks a lot.
 
Back
Top