devxlogo

Long File Names Can Be Confusing

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 LongFunction 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 IfEnd 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.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist