|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help trimming off filename from pathI've got a form where i need to pull both the directory of a filename
and the directory with the filename of an .inf file... I figured the easiest way to do this was to have an <input id=test type=file runat=server> control for the user to find the .inf file, and then make vb cut off the filename upon submission of the form. I just can't figure out how to trim off the filename leaving just the directory it's located in. just as a test i'm trying to display the content as follows Label1.Text = formINFLocation.Value.Trim(formDriverINF.FileName) I did this hoping to dynamically trim off any inf filename that is chosen... though it seems that the Trim function does not work the way i was assuming it did. Is there another way to remove the filename from this location? I have a hunch it's far more complicated than my simple idea here. :D "PvtPile" <derek.pe***@gmail.com> schrieb: Check out the 'System.IO.Path' class and its shared methods.> I've got a form where i need to pull both the directory of a filename > and the directory with the filename of an .inf file... I figured the > easiest way to do this was to have an <input id=test type=file > runat=server> control for the user to find the .inf file, and then make > vb cut off the filename upon submission of the form. I just can't > figure out how to trim off the filename leaving just the directory it's > located in. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Show quote
Hide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message Yeah, System.IO.Path.GetDirectoryName gets the directory path you want :)news:%23ZDAERjbGHA.4932@TK2MSFTNGP03.phx.gbl... > "PvtPile" <derek.pe***@gmail.com> schrieb: >> I've got a form where i need to pull both the directory of a filename >> and the directory with the filename of an .inf file... I figured the >> easiest way to do this was to have an <input id=test type=file >> runat=server> control for the user to find the .inf file, and then make >> vb cut off the filename upon submission of the form. I just can't >> figure out how to trim off the filename leaving just the directory it's >> located in. > > Check out the 'System.IO.Path' class and its shared methods. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> So... Dim dirName As String = System.IO.Path.GetDirectoryName(...) :) HTH,Mythran try something along the lines of this:
UNTESTED Label1.Text = strPath.Substring(0, strPath.LastIndexOf("\")) that should give you the directory with the last \ ex: C:\SomeFolder\AnotherFolder\ -- -iwdu15 "iwdu15" <jmmgoalsteratyahoodotcom> schrieb: Directory paths in Windows typically do not include a trailing backslash. > Label1.Text = strPath.Substring(0, strPath.LastIndexOf("\")) > > that should give you the directory with the last \ > > ex: > > C:\SomeFolder\AnotherFolder\ In addition, note that not all systems necessarily use "\" as path separator character and thus your code won't work on these systems. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> thats a good point...my code would only work on the systems that use the \
path separator, thanks for the correction -- -iwdu15 Thanks iwdu15
That worked great! I hate it when people just say "It worked, thanks." without showing us the results... so here it is. Dim pathname As String = FileUpload.Value Label1.Text = (FileUpload.Value.Substring(0, FileUpload.Value.LastIndexOf("\"))) Again, thanks for all the help on this topic! glad i could help, just make sure you check Herfried's post above about your
solution -- -iwdu15 Indeed valid. The reason, howerver, is that i need this input is so
that i can use it in a shell command at a later date. The format that was extracted was exactly what was needed. The directory will be used to reference a file on an nt machine only. Great work guys... you guys are too smart!
Re: making datareaders
Substring question Create Registry Entry On Install. Support for multiple database How To Create Login Password Protected Database myMAPISession.SignOn() How do you launch a vbscript within vb.net? msmapi32.ocx Accessing existing Excel Workbook from complete path VB2005 Short address pointer |
|||||||||||||||||||||||