GetShortPathName…again

Man, I hate it when I can’t find old code to reuse. Maybe if I post it here I’ll at least be able to find it next time it’s wanted. *Heavy, theatrical, sigh*

Edited to add a bit more info.

I’ve gotten far too use to the casual, sloppy, chatty style of Facebook, I guess.

I’m writing code, in VFP, that will iterate through directories, collect all PDFs, and merge them using GhostScript. I want the full path and file names for one purpose, but Ghostscript seems to require short file names. At least so far as I can tell it stumbles with file names delimited with quotes. So, in short, I need both short and long paths, and I can iterate using native VFP functions with either long or short paths, but not both. Hence, my desire to collect long filenames, but convert to short paths to pass to GhostScript.

* Example
?GetShortPathName_VFP( GetFile() )

Function GetShortPathName_VFP (tcLongName)

	Assert Vartype( tcLongName ) = "C" ;
		Message "Did you mean to pass a bad parameter to " + ;
		Program( Program(-1) -1 ) + "?"

	Local lcFName, lnFName

	DeclareDlls_gspn()

	lcFName = Space(255)

	lnFName = GetShortPathName( tcLongName, @lcFName, 255)

	ClearDlls_gspn()

	Assert lnFName > 0 Message Program() + " failed."

	Return Left( lcFName, lnFName )

Endfunc

Function DeclareDlls_gspn
	Declare Integer GetShortPathName In Win32API As ;
	GetShortPathName String, String, Integer
	Return
Endfunc

Function ClearDlls_gspn
	Clear Dlls "GetShortPathName"
	Return
Endfunc
Advertisements

2 thoughts on “GetShortPathName…again

    • You answered your question…ADIR returns “either the long or the short filenames”. I need both. I am grabbing the long paths, but also need the short paths for GhostScript. ADIR won’t do both at once. And it would be silly to do it twice, and then have to relate the arrays. It’s so much easier to use the Windows API.

      p.s. Thanks for the directory recurse link. I can more or less write that sort of code in my sleep at this point.

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