Return filename only?

Return filename only?

Anonymous
Not applicable
255 Views
4 Replies
Message 1 of 5

Return filename only?

Anonymous
Not applicable
Hi,

Is there an easy way in VBA to return just the filename from a full
path? e.g.:

C:\this\that\theother\filename.dwg -> extract "filename" only?

(Sort of like dos_splitpath in doslib)

Thanks,
Iqbal.
0 Likes
256 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Iqbal,
You can use: ThisDrawing.Application.ActiveDocument.Name (retrieves
just the name)

instead of: ThisDrawing.Application.ActiveDocument.FullName (retrieves
path and name)

or if you want just part the name use:
Mid$(ThisDrawing.Application.ActiveDocument.Name, 5, 1) (counts five
spaces and takes 1 character)

-Josh

Iqbal Lotey wrote:

> Hi,
>
> Is there an easy way in VBA to return just the filename from a full
> path? e.g.:
>
> C:\this\that\theother\filename.dwg -> extract "filename" only?
>
> (Sort of like dos_splitpath in doslib)
>
> Thanks,
> Iqbal.
0 Likes
Message 3 of 5

Anonymous
Not applicable
p.s.- in case the path your looking at isn't the path of the current drawing
( I assumed), then you can use the mid$ function I mentioned last. It will
work with any string.
-Josh

Minkwitz Design wrote:

> Iqbal,
> You can use: ThisDrawing.Application.ActiveDocument.Name (retrieves
> just the name)
>
> instead of: ThisDrawing.Application.ActiveDocument.FullName (retrieves
> path and name)
>
> or if you want just part the name use:
> Mid$(ThisDrawing.Application.ActiveDocument.Name, 5, 1) (counts five
> spaces and takes 1 character)
>
> -Josh
>
> Iqbal Lotey wrote:
>
> > Hi,
> >
> > Is there an easy way in VBA to return just the filename from a full
> > path? e.g.:
> >
> > C:\this\that\theother\filename.dwg -> extract "filename" only?
> >
> > (Sort of like dos_splitpath in doslib)
> >
> > Thanks,
> > Iqbal.
0 Likes
Message 4 of 5

Anonymous
Not applicable
Hi!Iqbal,

you can use the follwing function for VBA to get the filename only from any
path string.
Actually it's lot more easier to do the same in VB6.0.

'_________________________________
Public Function f_getFilename(ps_str As String) As String
'function to extract the filename from any path
Dim pi_i As Integer
pi_i = 1

While pi_i <> 0
pi_i = InStr(1, ps_str, "\")
ps_str = Right(ps_str, Len(ps_str) - pi_i)
Wend

pi_i = InStr(1, ps_str, ".")
f_getFilename = Left(ps_str, pi_i - 1)
End Function
'_________________________________
--
bye,

P.Murali
Iqbal Lotey <1@2.3> wrote in message news:383C5063.4B943CDB@2.3...
>
> Hi,
>
> Is there an easy way in VBA to return just the filename from a full
> path? e.g.:
>
> C:\this\that\theother\filename.dwg -> extract "filename" only?
>
> (Sort of like dos_splitpath in doslib)
>
> Thanks,
> Iqbal.
0 Likes
Message 5 of 5

Anonymous
Not applicable
If you are using the "preview" edition of VBA (R14.00) you may have a problem
getting just the file name. I know I did. The ".Name" property would always
return the full path just like the ".FullName" property.

I wrote a small function to take care of the problem until I could upgrade to
R14.01.
At least I think R14.01 fixed it.
I know R2K returns just the file name when you use
"ThisDrawing.Application.ActiveDocument.Name".

1@2.3 (Iqbal Lotey) wrote in <383C5063.4B943CDB@2.3>:

>Hi,
>
> Is there an easy way in VBA to return just the filename from a full
>path? e.g.:
>
> C:\this\that\theother\filename.dwg -> extract "filename" only?
>
> (Sort of like dos_splitpath in doslib)
>
> Thanks,
> Iqbal.
0 Likes