No more “double quotes” for me!
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:
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)!
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.