473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help trimming off filename from path

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.
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

May 2 '06 #1
8 2801
"PvtPile" <de*********@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/>
May 2 '06 #2
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
May 2 '06 #3

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"PvtPile" <de*********@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/>


Yeah, System.IO.Path.GetDirectoryName gets the directory path you want :)

So...

Dim dirName As String = System.IO.Path.GetDirectoryName(...)

:)

HTH,
Mythran

May 2 '06 #4
"iwdu15" <jmmgoalsteratyahoodotcom> schrieb:
Label1.Text = strPath.Substring(0, strPath.LastIndexOf("\"))

that should give you the directory with the last \

ex:

C:\SomeFolder\AnotherFolder\


Directory paths in Windows typically do not include a trailing backslash.
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/>

May 2 '06 #5
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!

May 2 '06 #6
thats a good point...my code would only work on the systems that use the \
path separator, thanks for the correction
--
-iwdu15
May 2 '06 #7
glad i could help, just make sure you check Herfried's post above about your
solution
--
-iwdu15
May 3 '06 #8
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!

May 3 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter A. Schott | last post by:
Got a strange scenario going on here in that I could have sworn this worked yesterday. I am issuing binary retrieval calls to an FTP server, writing to a file, close the file, then removing the...
7
by: ColinWard | last post by:
Hello. I use the following line which returns the path of a file and adds it to a listbox. How can I modify this line so that it only returns the filename and not the entire path? -->...
6
by: cj | last post by:
Lets just take this example I'm looking at now. I'm looking at the help screen titled .NET Framework Class Library FolderBrowserDialog Class . It gives an example at the bottom that begins with:...
5
by: Tom | last post by:
Hi: I'm using the Leban's ReportToPDF solution and have encountered a small problem. I'm calling the code using the following: Call ConvertReportToPDF(strReportName, , , True, True) Where...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
by: Enyi | last post by:
Situation : Need to get a list of files in a directory, but I am currently getting the whole path of the file (Example: "C:\A Folder\Another Folder\file.txt"). What I want is just the filename and...
16
by: ^MisterJingo^ | last post by:
Hi all, I have a variable called root which contains (E:\Web\Websites\fileBrowse\) and then I have a variable called path which uses root, and adds directories on to it (this is part of a file...
12
by: DFS | last post by:
I need to scan various network folders and capture all the filenames and create dates. ======================================================= 1st effort used the typical drive scan cFile =...
13
by: Effix | last post by:
Hi everybody I have yet another problem, actually two but lets start with this one :-) Im making a very simple gallery or at least I think its simple. I have already made a upload script that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.