File Names: List Long file Names from Database List of short file names

B

Ben

Hi

We have a list of file paths and short file names in our database.

We need to loop through them all, picking up the long file name from the
file itself and check that the long file name does not include a "~"
character.

I have the short file name and path in a variable (eg
"c:\data\123442~1.doc") how can I get the long file name from this data.

Any advice would be much appreciated.

Thanks
B
 
J

jayeldee

Good ol' Dir( ) from vb6 will do what you want.

Dim filename As String = "C:\somelo~1.txt"
Console.WriteLine(Dir(filename))
Console.ReadLine()
Exit Sub

^ Outputs 'somelongfilename.txt' to the console.

That's the quickest way I can think of. I looked at the System.IO.File
and although it accepts both long names and the 8dot3 file names, I
couldn't find a way to switch between the two.

John
 
G

Guest

I use the below for getting a short path from a long path so there is
probably an API function for getting a longpath from a short paty. Hope this
helps.

Protected Declare Ansi Function GetShortPathName Lib "kernel32.dll" Alias
"GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As
StringBuilder, ByVal cchBuffer As Integer) As Integer

Protected Function GetShortPath(ByVal file As String) As String
Dim buffer As StringBuilder = New StringBuilder(file.Length + 1)
Dim ret As Integer = GetShortPathName(file, buffer, buffer.Capacity)
If ret = 0 Then ' Error
Return ""
Else ' Success
Return buffer.ToString()
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top