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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog 2

Status
Not open for further replies.

Ablecken

Programmer
Jun 5, 2001
130
US
How do I get only the folder name with the common dialog control. if i cant what is the best way to do it. i want the folder that a certain file is in. not the file name. like if i was looking for c:\somedir\somefile.file all i want is c:\somedir.

Thanx

able
 
HI.

Hope this helps. You will end up with two variables. One with the full path, minus the file. And one with just the file.

Dim sPath As String
Dim sFile As String
Dim sFullName As String
Dim iSlash As Integer

sFullName = commondialog.FileName '


iSlash = InStrRev(sFullName, "\")
sPath = Left(sFullName, iSlash - 1)
sFile = Mid(sFullName, iSlash + 1)


debug.print "Path = " & sPath
deug.print "File = " & sFile

Hope it helps
 
Try this

Text1 = Replace(CommonDialog1.FileName, CommonDialog1.FileTitle, "")
David Paulson

 
You could just parse out the file path string, or am I missing something? Anything is possible, the problem is I only have one lifetime.
[cheers]
 
thanx they all worked but i ended up using dpaulsens suggestion. It was the shortest. Thanx a lot
 
Or,

Dim FSys as New FileSystemObject
Set file = FSys.GetFile(c:\somedir\somefile.fil)
MyPath = file.path

And you can get other useful properties this way

file.DateCreated
file.Size
file.Attributes
file.DateLastAccessed
file.ParentFolder
file.ShortName ( useful for what it would look like in DOS )

and more.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top