|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File Names: List Long file Names from Database List of short file namesHi
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 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 Thanks John thats perfect!!
B Show quoteHide quote "jayeldee" <jayel***@gmail.com> wrote in message news:1146837935.065824.131630@j73g2000cwa.googlegroups.com... > 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 > 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 -- Show quoteHide quoteDennis in Houston "Ben" wrote: > Thanks John thats perfect!! > > B > > "jayeldee" <jayel***@gmail.com> wrote in message > news:1146837935.065824.131630@j73g2000cwa.googlegroups.com... > > 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 > > > > > There sure is!
http://www.pinvoke.net/default.aspx/kernel32.GetLongPathName ^ has the C# syntax for the call, which shouldnt' be that hard to convert with the code Dennis posted. John (also in Houston!) |
|||||||||||||||||||||||