Home > C/C++, Delphi, Programming, Tech > No more “double quotes” for me!

No more “double quotes” for me!

I was having a problem in some code of mine where it worked perfectly when called on a  file path with no spaces, but failed on a folder with spaces (even when using double quotes). The solution that fixed this lingering issue was the following API call. I’m done double-quoting.
I didn’t even know this function existed within Windows (I assumed it would have only existed in a  framework or programming language itself — if pre-built at all).
Of course, this comes included with the JCL!
JclFileUtils.PathGetShortName
Instead of double-quoting paths to files/folders so things don’t get mucked up when shelling-out, instead call

I was having a problem in some code of mine where I was executing an external process and everything worked perfectly when called on a  file path with no spaces, but failed on a folder with spaces (even when using double quotes). The solution that fixed this lingering issue was the following API call:

GetShortPathName

C++

DWORD WINAPI GetShortPathName(

__in   LPCTSTR lpszLongPath,

__out  LPTSTR lpszShortPath,

__in   DWORD cchBuffer

);

I didn’t even know this function existed within Windows (I assumed it would have only existed in a  framework or programming language itself — if pre-built at all).

Of course, this comes included with the open-source Delphi Jedi Code Library (JCL)!

JclFileUtils.PathGetShortName

Instead of double-quoting paths to files/folders so things don’t get mucked up when shelling-out, instead consider calling GetShortPathName. If you need to convert this back to it’s full form, just call GetFullPathName. Easy as pie.

Advertisements
Categories: C/C++, Delphi, Programming, Tech
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s