Home All Groups Group Topic Archive Search About

vb.net "getting the base name of a file"

Author
8 Dec 2006 12:28 AM
samadams_2006
Hello,

Suppose in VB.NET I have a file at:

c:\bitmaps\image1.bmp

and I want to get the "basename" (ie:  image1)
and the "path" (ie:  c:\bitmaps\)

How do I go about it?  It doesn't appear that  io.file has these
features?

Thanks.

Author
8 Dec 2006 12:45 AM
Dennis
I think one of the easiest ways is to use the FileInfo class.
--
Dennis in Houston


Show quoteHide quote
"samadams_2***@yahoo.ca" wrote:

>
> Hello,
>
> Suppose in VB.NET I have a file at:
>
> c:\bitmaps\image1.bmp
>
> and I want to get the "basename" (ie:  image1)
> and the "path" (ie:  c:\bitmaps\)
>
> How do I go about it?  It doesn't appear that  io.file has these
> features?
>
> Thanks.
>
>
Author
8 Dec 2006 1:06 AM
Andrew Backer
Look at System.IO.Path.Get<what you need>()

samadams_2***@yahoo.ca wrote:
Show quoteHide quote
> Hello,
>
> Suppose in VB.NET I have a file at:
>
> c:\bitmaps\image1.bmp
>
> and I want to get the "basename" (ie:  image1)
> and the "path" (ie:  c:\bitmaps\)
>
> How do I go about it?  It doesn't appear that  io.file has these
> features?
>
> Thanks.
Author
8 Dec 2006 5:59 AM
RobinS
If you're using VB2005:

Console.Writeline(Path.GetDirectoryName("C:\bitmaps\image1.bmp"))

will give you "C:\Bitmaps"

Path also has GetFileName (image1.bmp), GetExtension (bmp),
GetFileNameWithoutExtension (image), GetPathRoot (C:\) ....

Robin S.
--------------------------
<samadams_2***@yahoo.ca> wrote in message
Show quoteHide quote
news:1165537699.568234.3040@j44g2000cwa.googlegroups.com...
>
> Hello,
>
> Suppose in VB.NET I have a file at:
>
> c:\bitmaps\image1.bmp
>
> and I want to get the "basename" (ie:  image1)
> and the "path" (ie:  c:\bitmaps\)
>
> How do I go about it?  It doesn't appear that  io.file has these
> features?
>
> Thanks.
>