Home All Groups Group Topic Archive Search About

how can I tell if it is a folder or a non-folder file

Author
11 Dec 2006 1:38 AM
Franky
Given the path to a file how can I tell if it is a folder or a non-folder
file?



Thanks

Author
11 Dec 2006 3:35 AM
RobinS
If you have VB2005, check out the Path class.

Dim file As String = "C:\MyApp\Bin\MyApp.exe"
Path.GetDirectoryName(file)   --> C:\MyApp\Bin
Path.GetFileName(file)        --> MyApp.exe
Path.GetFileExtension(file)   --> .exe
Path.GetFileNameWithoutExtension(file)  --> MyApp

I would think if you do a GetDirectoryName on it, and it
returned the same value as was already in it, you could
assume it's a folder?

Robin S.
----------------------------------------
Show quoteHide quote
" Franky" <frankieNOSPAM@a-znet.com> wrote in message
news:%23lsdEUMHHHA.3668@TK2MSFTNGP02.phx.gbl...
> Given the path to a file how can I tell if it is a folder or a
> non-folder file?
>
>
>
> Thanks
>
>
Author
11 Dec 2006 3:41 AM
Michael C
" Franky" <frankieNOSPAM@a-znet.com> wrote in message
news:%23lsdEUMHHHA.3668@TK2MSFTNGP02.phx.gbl...
> Given the path to a file how can I tell if it is a folder or a non-folder
> file?

Folder.Exists or File.Exists I think.
Show quoteHide quote
>
>
>
> Thanks
>
>
Author
11 Dec 2006 12:26 PM
C-Services Holland b.v.
Franky wrote:
> Given the path to a file how can I tell if it is a folder or a non-folder
> file?
>
>
>
> Thanks
>
>

Off the top of my head...

If File.GetAttributes(cFileName) And FileAttributes.Directory Then
    MsgBox(cFilename + " is a directory")
Else
    MsgBox(cFilename + " is a file")
EndIf

Assuming the file or directory actually exists.

--
Rinze van Huizen
C-Services Holland b.v
Author
11 Dec 2006 3:19 PM
Franky
Wow, three approaches.
thanks to all


Show quoteHide quote
" Franky" <frankieNOSPAM@a-znet.com> wrote in message
news:%23lsdEUMHHHA.3668@TK2MSFTNGP02.phx.gbl...
> Given the path to a file how can I tell if it is a folder or a non-folder
> file?
>
>
>
> Thanks
>
>