Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: execute a file

by RhetTbull (Curate)
on Apr 13, 2001 at 17:34 UTC ( #72334=note: print w/ replies, xml ) Need Help??


in reply to Re: execute a file
in thread execute a file

There may be a simpler way to "DOSify" the file name but this works for me. There's a Win32 API call GetShortPathName that returns the DOSified path name. You can call it from perl using Win32::API. The prototype is

DWORD GetShortPathName( LPCTSTR lpszLongPath, // null-terminated path string LPTSTR lpszShortPath, // short form buffer DWORD cchBuffer // size of short form buffer );
The equivalent call in perl can be written like this:
use Win32::API; #import the function my $GetShortPathName = new Win32::API("kernel32","GetShortPathName",[ +P,P,N ],N); if (not defined $GetShortPathName) { die "could not import GetShortPathName"; } #the name we want to convert $longname = "C:\\Program Files\\Microsoft Office\\Office\\OLREAD9.TXT" +; #create a string big enough to hold the shortname $shortname = " " x 80; #retval will be length of the DOSified short name $retval = $GetShortPathName->Call($longname,$shortname,80); #trim the trailing blanks #recall that $shortname = " " x 80 #and retval is the length of the name returned by GetShortPathName $shortname = substr($shortname,0,$retval); print "longname = \n\"$longname\", \nshortname = \n\"$shortname\"";
On my system, this returns
C:\temp>perl shortname.pl longname = "C:\Program Files\Microsoft Office\Office\OLREAD9.TXT", shortname = "C:\PROGRA~1\MICROS~3\Office\OLREAD9.TXT" C:\temp>


Comment on Re: Re: execute a file
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://72334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2014-07-28 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (206 votes), past polls