Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 4, 1997



Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js

Long File Names Can Be Confusing

If you want to open Paint with a file from your application, it's better to convert the path of the file you want to open from long to short names. Doing so is wise because in some situations-if your path contains spaces, for example-Paint may refuse to work properly. Before passing a file name to Paint, convert it to short names with this routine, which takes advantage of the Win32 API:
Declare Function GetShortPathName Lib "kernel32" Alias _
	"GetShortPathNameA" (ByVal lpszLongPath As String, _
	ByVal lpszShortPath As String, _
	ByVal cchBuffer As Long) As Long

Function ShortName(LongPath As String) As String
	Dim ShortPath As String
	Const MAX_PATH = 260
	Dim ret&
	ShortPath = Space$(MAX_PATH)
	ret& = GetShortPathName(LongPath, ShortPath, MAX_PATH)
	If ret& Then
		ShortName = Left$(ShortPath, ret&)
	End If
End Function
This trick may prove useful with any application you pass file names to. It would be smart to try passing "strange" file names/paths to make sure.
Andrea Nagar
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date