Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get filename with VB .Net

Status
Not open for further replies.

ter79

IS-IT--Management
Jul 11, 2001
106
US
I need to retrieve the full file name of a file that resides within a specific folder. Currently I'm using this code

Dim FileLoc As String, FileName As String

FileLoc = "\\servername\FileLocation\"
FileName = System.IO.Path.GetFileName(FileLoc)

MessageBox.Show(FileName)

However the message box is empty. The folder should have a file titled something like "DI.99990812.99999. Note that the file name is going to change each time the file is created, the only thing that won't change is the "DI" part of the file name.

Thanks in advance
 
Code:
Dim objFolder as System.IO.DirectoryInfo
Dim objFile as System.IO.FileInfo
Dim FileLoc as String

FileLoc = "\\servername\FileLocation\"

objFolder = New DirectoryInfo(FileLoc)

For Each objFile In objFolder.GetFiles
   Messagebox.show(objFile.Name)
Next
 
Thanks that worked...

However, the folder is going to have different files with different names and I need the specific filename of the file that starts with DI

Thanks
 
I meant to say that worked for getting all the filenames in the directory but I need to be specific on which filename I return
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top