Help - Search - Members - Calendar
Full Version: vb.net system.io
ieXbeta Board > Tech > Developer Center
Crimson Tide
I need to access the system.io.fileinfo to populate a varialbe with a folder name.

Folder strucuture is like such

Companies
AB Construcion
Photos
image1.jpg
Presentation
powerpoint1.ppt
XZY Pest Control
Photos
image1.jpg
Presentation
powerpoint.ppt
Excel
costs.xls

I need to always get the AB Constrution or XZY Pest into the variable. I have tried

MsgBox(foundFileInfo.Directory.Parent.Name)
and
MsgBox(foundFileInfo.DirectoryName)

This tends to work some of the time, but if there is a folder inside photos like 2004, 2005 then it screws it up.

I can map a network drive to the root of companies.

Is there maybe a way I can read in the full path (foundFileInfo.DirectoryName) and trim from the first / to the second / say if my path was

g:\xzy pest control\docs\word.doc

Can I just pull out xzy pest control with a trim type statement?

I have most of the rest of this routine written.

President Killer
Have you tried...

foundFileInfo.Directory.Name

...?
Crimson Tide
THanks for the reply but that returns the parent folder of the file, and if the folder structure was standard (which its not) this would work, but it could be 1 level to 7 levels deep. I need the root most folder and there is a . somthing for that to, but it just gives me the drive letter.

After more research I think I need to use the string.split method or a regular expression to parse out the values I need.

Other suggestions are welcome.
President Killer
Ahhh, I think I understand now. I've made a little example:

CODE
Dim fiInfo As System.IO.FileInfo
Dim strPath As String
fiInfo = New System.IO.FileInfo("C:\WINDOWS\system32\config\systemprofile\ntuser.dat")
strPath = fiInfo.Directory.FullName.Remove(0, fiInfo.Directory.Root.FullName.Length) 'This code removes the Root from the path
strPath = strPath.Substring(0, strPath.IndexOf("\")) 'This code only leaves the first Parent folder in the path: "WINDOWS"
MessageBox.Show(strPath)


Test it and see if it that's what you need. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.