Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need legal DOS paths... 3

Status
Not open for further replies.

BlindPete

Programmer
Jul 5, 2000
711
US
Hello All,<br><br>I need to pass DOS style path names to another program from VFP, however I can not figure a way to get the legal DOS name of the path.&nbsp;&nbsp;Anyone have a trick on how to convert long path names to DOS 8 character names?<br><br>For example change:<br><br>C:\My Documents\Excel Sheets\<br>C:\My Documents\Excel Stuff\<br>&nbsp;-to-<br>C:\MYDOCU~1\EXCELS~2\<br>C:\MYDOCU~1\EXCELS~1\<br><br> <p> <br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>
 
run dir c:\windows\*.* &gt; c:\text.txt<br>select 0<br>create table C:\FILESDBF.DBF (NAME c(100))&nbsp;&nbsp;&& or whatever you want<br>use c:\filesdbf<br>append from c:\text.txt type sdf<br>DosFileName = alltrim(substr(FILESDBF.NAME,1,12))<br> <p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br>
 
Filer.dll to the rescue.<br><br>Go to the VFP on-line help for &quot;Filer&quot;, then choose Filer.dll.&nbsp;&nbsp;Scroll down to the section on File Collection Properties and note that one of the properties is AlternateName, which will be the short, or 8.3, file name.<br><br>Of course, if you have to distribute this in a runtime, this solution won't work ;-) <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Thanks,<br><br>As Robert surmised filer won't help - it must be distributed.<br><br>I was hoping to avoid using txt files but I'll give it go anyhow. <br><br>Thanks<br><br> <p> <br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>
 
Try this:<br><br><FONT FACE=monospace>* GetShortPathName<br><br>PROCEDURE GetDOS83<br>LPARAMETERS tcLongPathName<br><br>* Accepts a path as a parameter.&nbsp;&nbsp;<br>* If the path is invalid or missing then GetFile gets one<br>* If you need a UI interface out of this then remove it<br><br>LOCAL lcLongFile, lcBuffer, lnBufferSize, lnShortPathLen, lcShortPath<br><br>* Validate parameter<br>IF EMPTY(tcLongPathName) OR ;<br>&nbsp;&nbsp;&nbsp;VARTYPE(tcLongPathName) &lt;&gt; 'C' OR ;<br>&nbsp;&nbsp;&nbsp;!FILE(tcLongPathName)<br> lcLongFile = GETFILE()<br> IF !FILE(lcLongFile)<br> * user cancelled or again entered invalid stuff<br> RETURN&nbsp;&nbsp;&& Loser!<br> ENDIF<br>ELSE<br> * the path is valid<br> lcLongFile = tcLongPathName<br>ENDIF<br><br>DECLARE INTEGER GetShortPathName IN Win32API ;<br>&nbsp;&nbsp;&nbsp;STRING&nbsp;&nbsp;@cLongPath, ;<br>&nbsp;&nbsp;&nbsp;STRING&nbsp;&nbsp;@cShortPathBuff, ;<br>&nbsp;&nbsp;&nbsp;INTEGER nBuffSize<br><br>lcBuffer = SPACE(511)<br>* should this be set to the maximum length allowed for a long path name?<br>lnBufferSize = 511<br>lnShortPathLen = GetShortPathName(lcLongFile, @lcBuffer, @lnBufferSize)<br>lcShortPath = LEFT(lcBuffer, lnShortPathLen)<br>RETURN lcShortPath</font> <p>John Durbin<br><a href=mailto: > </a><br><a href= > </a><br>ICQ VFP ActiveList #73897253
 
With a few slight mods it works perfect.&nbsp;&nbsp;Thanks for the sample John!<br><br>I have stayed away from API routines I played with them a few years ago but ran into problems between platforms.&nbsp;&nbsp;By making use of API am I going to have problems between platforms (2000/NT4/98/95) ????<br> <p> <br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>
 
Nope its just VFP can't do all the things with arrays and stuff VB and C does.&nbsp;&nbsp;But the ones that work, work.&nbsp;&nbsp;I should have checked over that code.&nbsp;&nbsp;I see an out of place ENDIF and questions I had but you get it anyways.&nbsp;&nbsp;Why API is just getting going, I mean at least more, in VFP I don't know.&nbsp;&nbsp;It works great.&nbsp;&nbsp;I'm trying to build a library.&nbsp;&nbsp;Rick Strahl has many great functions in his wwRegistry.prg or something at west-wind.com&nbsp;&nbsp;If anyone can't find it I will and post them.&nbsp;&nbsp;Maybe in a FAQ.&nbsp;&nbsp;Glad I'm good for something.&nbsp;&nbsp;Rough couple past days&nbsp;&nbsp;:)&nbsp;&nbsp; <p>John Durbin<br><a href=mailto: > </a><br><a href= > </a><br>ICQ VFP ActiveList #73897253
 
Been there!&nbsp;&nbsp;Hang in there! and Thanks again! <p> <br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>
 
FWIW,<br>&nbsp;&nbsp;GetShortPathName can be used to convert directories as well as pathes to 8.3 format.<br><br>lcLongPath='C:\Program Files\Microsoft Visual Studio\' && convert directory<br>OR<br>lcLongPath='C:\Program Files\Microsoft Visual Studio\Vfp.exe' && convert path<br><br>Just be sure that the target, directory or file, exists or else GetShortPathName will return an error. That one bit me in the buttox yesterday. I was generating unique filenames and using this function to convert the path to 8.3 format, but since the file didnt exist on disk, WHAM!...Error 87..Invalid parameter. Nowhere in the documentation does it say the target has to exist on disk....but...it does. <p>Jon<br><a href=mailto: > </a><br><a href= > </a><br>Carpe Diem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top