Finding the current directory

  • Thread starter Thread starter Robert Vivian
  • Start date Start date
R

Robert Vivian

I am trying to open a file in the current directory but specifying only the
file name results in an error indicating that the file is not found. When I
execute a CurDir function I receive only the path to the current directory.
Is there something that I am missing?
 
Robert Vivian said:
I am trying to open a file in the current directory but specifying only the
file name results in an error indicating that the file is not found. When I
execute a CurDir function I receive only the path to the current directory.
Is there something that I am missing?

So you merge them....!!

Path & FileName.
i don't know how to you try to open it, but probably with Shell function...?
You can open only the Filetype that have ClassName....!
Can you show us you code for more precision detail...?

Alessandro(IT)
 
Directory containing the file is C:\Documents and Settings\default\My
Documents\My Projects. Diectory returned by CurDir is C:\Documents and
Settings\default\My Documents. I would have expected My Projects to be
included in the path returned by CurDir but it is not so merging with the
filename accomplishes nothing. I do not understand why CurDir does not
include the current directory in the returned path.
 
Robert Vivian said:
Directory containing the file is C:\Documents and Settings\default\My
Documents\My Projects. Diectory returned by CurDir is C:\Documents and
Settings\default\My Documents. I would have expected My Projects to be
included in the path returned by CurDir but it is not so merging with the
filename accomplishes nothing. I do not understand why CurDir does not
include the current directory in the returned path.


I'm not sure because usually i use DAO Library, you are using ADO now
but i think you have also CurrentProject.Name......!
My DAO solution is this :
If you select in your Reference Library Microsoft DAO 3.xx you can use:

FullPath=CurrentDb.Name

Here you have the full Path, now to obtain the DirOnly you can use this
function and call it like this:

Path=GetPathPart(CurrentDb.Name)
FileName=ParseFileName(CurrentDb.Name)

Public Function GetPathPart(ByVal strPath As String) As String
'*****************************************************************
'Name : GetPathPart (Function)
'Purpose : Return Path name ONLY
'Author : Alessandro Baraldi
'Called by :
'Calls :
'Inputs : strPath="C:\Programmi\DataBase.mdb"
'Output : GetPathPart="C:\Programmi\"
'*****************************************************************
Dim intCounter As Integer
For intCounter = Len(strPath) To 1 Step -1
If Mid$(strPath, intCounter, 1) = "\" Then
Exit For
End If
Next intCounter
GetPathPart = Left$(strPath, intCounter)
End Function

Public Function ParseFileName(ByVal FileName As String) As String
'*****************************************************************
'Name : ParseFileName (Function)
'Purpose : Return File Name ONLY
'Author : Alessandro Baraldi
'Date : 23 gennaio 2002
'Called by :
'Calls :
'Inputs : strFileName="C:\Programmi\DataBase.mdb"
'Output : ParseFileName="Database.mdb"
'*****************************************************************
On Error GoTo Err_ParseFileName

ParseFileName = Dir(FileName)
Exit_ParseFileName:
Exit Function

Err_ParseFileName:
MsgBox Err.Description
Resume Exit_ParseFileName
End Function


Bye.
@Alex.
 
Robert Vivian said:
Directory containing the file is C:\Documents and Settings\default\My
Documents\My Projects. Diectory returned by CurDir is C:\Documents
and Settings\default\My Documents. I would have expected My Projects
to be included in the path returned by CurDir but it is not so
merging with the filename accomplishes nothing. I do not understand
why CurDir does not include the current directory in the returned
path.

CurDir() returns the Windows "current directory", which is not
necessarily the directory containing the database file. If you're using
Access 2000 or later you can get the directory containing the database
from CurrentProject.Path.
 
Dirk Goldgar said:
CurDir() returns the Windows "current directory", which is not
necessarily the directory containing the database file. If you're using
Access 2000 or later you can get the directory containing the database
from CurrentProject.Path.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Really better ADO solution.
Alessandro(IT).
 
Back
Top