bjwade62 Posted February 15, 2006 Posted February 15, 2006 I'm trying to get the portion of a folder name that comes after the last "\". For instance. k:\cortland\wade = wade k:\cortland\wade\arch = arch I've been trying to use a combination of Split and LastIndexOf but I'm not having any luck. Can anyone steer me in the right direction? Quote
Cags Posted February 15, 2006 Posted February 15, 2006 ' if path is a string object containing the full path then path.Substring(path.LastIndexOf("\") + 1) Quote Anybody looking for a graduate programmer (Midlands, England)?
Leaders snarfblam Posted February 15, 2006 Leaders Posted February 15, 2006 There is already a function that exists specifically for this purpose (and is independant of environment, meaning it will work on a platform where the path separator character is / instead of \). Dim FolderPath As String = "C:\\Documents And Settings\\MooCow" Dim SubFolderName As String = System.IO.Path.GetFileName(FolderPath) 'Shows "MooCow" MessageBox.Show(SubFolderName) I know the function's name is GetFileName, but syntactically a folder path and an extensionless file name are the same, with one exception. A folder path can be followed by a trailing backslash, which should be taken into consideration. Quote [sIGPIC]e[/sIGPIC]
Nate Bross Posted February 16, 2006 Posted February 16, 2006 Yes, because in VB dim FilePathOne as String = "C:\\MyDocuments\\Afolder\\somefile.txt" dim FilePathTwo as String = "C:/MyDocuments\\Afolder/somefile.txt" FilePathOne = FilePathTwo 'at least as far as System.IO is concerned Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.