Link to home
Start Free TrialLog in
Avatar of phred_the_cat
phred_the_cat

asked on

Calling documents from users harddrive

Ok,

I need to be able to access several templates in this program.  Currently I call them from "C:/documentlocation".

However, when I package this program, not sure where the documents will be installed (for example, the user may wish to have the program installed on his D: drive).  Is there an easy way to either:
a.  Set location of install at packaging time, so that I can ensure that my templates install to "C:/documentlocation" on the user computer

or, and perhaps better,

b.  Determine where the templates are located on the machine when the program is run, so that the program picks the proper template (and I avoid thoes awful errors)

thanks

(sorry bout low points, but almost out and still got a few ? left to finish the project)
Avatar of jrspano
jrspano
Flag of United States of America image

let the user find them the first time and then save off the dir they picked in the registry and look there next time.
ASKER CERTIFIED SOLUTION
Avatar of ShaneCourtrille
ShaneCourtrille

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richie_Simonetti
I am with ShaneCourtrille.
jrspano, i would with you too, but i dodn't trust on end-users and we could get some more calls to support service.
here is some code to locate a file...what you can do is put a file name "TEMPLATES.923" or something with them and run this code to get the full path of where the templates are...

us it like this: MsgBox FindFile("c:\", "templates.txt")

GOOD LUCK :)


''''''''''

Declare Function SearchTreeForFile Lib "IMAGEHLP.DLL" _
    (ByVal lpRootPath As String, _
    ByVal lpInputName As String, _
    ByVal lpOutputName As String) As Long
   
Public Const MAX_PATH = 260

Public Function FindFile(RootPath As String, _
    FileName As String) As String
   
    Dim lNullPos As Long
    Dim lResult As Long
    Dim sBuffer As String
   
    On Error GoTo FileFind_Error
   
    'Allocate buffer
    sBuffer = Space(MAX_PATH * 2)
   
    'Find the file
    lResult = SearchTreeForFile(RootPath, FileName, sBuffer)
   
    'Trim null, if exists
    If lResult Then
        lNullPos = InStr(sBuffer, vbNullChar)
        If Not lNullPos Then
            sBuffer = Left(sBuffer, lNullPos - 1)
        End If
        'Return filename
        FindFile = sBuffer
    Else
        'Nothing found
        FindFile = vbNullString
    End If
   
    Exit Function
   
FileFind_Error:
    FindFile = vbNullString
   
End Function
Avatar of glass_cookie
glass_cookie

Hi!

Here's a file for you over the net.  Simply set the filename or extention (ie. *.tmp) to find out where the files are.

For interest sake, this one scans every and will list every file with the string that you want.  You'll have to know what same string exists in all your template files : )

Download...
http://www.vb-helper.com/Howto/findstr.zip
Description: Search files matching a pattern below a directory for a string (5K)

Thios one lists out all files matching a pattern.

Download...
http://www.vb-helper.com/Howto/search2.zip
Descrition: Search for files matching a pattern and show their total size (3K)

Well, you may want to merg the 2 in case there are 2 folders with different templates (from different programs) but using the same extention.

That's it!

glass cookie : )