That looks pretty cool. I take it that the Wscript run (as opposed to the vfp 
run) call prevents the FileToStr
from ever firing too soon... yes? 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Reidar Sjoen
Sent: Saturday, September 08, 2007 1:27 PM
To: ProFox Email List
Subject: RE: SUBST.EXE api

Lew,

I culled this out of some code I use.
This isn't an api, but it works well for me in vfp.
hope it helps.

--Reidar
 
*SubstedDrivesArray(@aArray)
* Returns number of substed drives
* Fills in aArray[cDrive,cPath]
* uses WSH,%Comspec%
*NO error checking

        lParameters aSubsted
        
        local nDrives,nDrive,nSubsted,nResult
        local cTempFile,cList,cLine,cDrive,cPath,cRunDos
        local oShell
        Local array aList[1]
        
        Store 0  to nDrives,nDrive,nSubsted,nResult
        Store "" to  cTempFile,cList,cLine,cDrive,cPath,cRunDos,aList
        
        cTempFile = Addbs(GetEnv("temp")) + Sys(2015) + ".tmp"
        cRunDos   = "Subst > " + m.cTempFile
         
        oShell    = createobject("WScript.Shell")
        
        nResult   = oShell.Run("%COMSPEC% /c " + m.cRunDos , 0,.T.)
        
        oShell    = .null.                      && Done with this

        cList     = FileToStr(m.cTempFile)
                
        Delete File (m.cTempFile) && Done with this
        
        nDrives = ALines(aList,m.cList,.t.)
        
        for nDrive = 1 to m.nDrives
        
                        *Line Ex:       M:\: => F:\M
                cLine  = aList[m.nDrive]
                cDrive = Left(m.cLine,3)
                cPath  = Alltrim(Substr(m.cLine,8))
                
                        * validate it
                if (At(":\",m.cDrive) = 2 ;
                  and At(":\",m.cPath) = 2 )

                        nSubsted = m.nSubsted + 1  
                        
                        dime aSubsted[m.nSubsted,2]
                        aSubsted[m.nSubsted,1] = Left(m.cDrive,2)
                        aSubsted[m.nSubsted,2] = m.cPath

                EndIf           && validate
                
        Next && nDrive

        Return m.nSubsted               &&      >>EXIT>>>>>>>>  



[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to