How to get complete path?

J

Jacques Oberto

Hi All,

I am using "folderBrowserDialog.SelectedPath" to obtain a user
selected path. Unfortunately the path is missing the trailing backslash.
Is there a way to obtain the complete path with "\" programmatically ?
Thanks,

Jacques
 
J

Jacques Oberto

"Jacques Oberto" a écrit
Hi All,

I am using "folderBrowserDialog.SelectedPath" to obtain a user
selected path. Unfortunately the path is missing the trailing backslash.
Is there a way to obtain the complete path with "\" programmatically ?
Thanks,

The really annoying part is that when the root directory is selected, the
trailing backslash is obtained:

c:\ versus c:\test

Jacques
 
P

Peter Duniho

Hi All,

I am using "folderBrowserDialog.SelectedPath" to obtain a user
selected path. Unfortunately the path is missing the trailing backslash.
Is there a way to obtain the complete path with "\" programmatically ?

Why do you want the path in a specific format? If you are trying to use
that path to assemble a new path, just use the Path.Combine() method.
..NET will take care of putting any necessary directory separators in there
for you.

You can in fact also get the Path class to normalize the path, putting the
last separator on the string. But it's usually not actually necessary to
do so.

Pete
 
J

Jacques Oberto

Peter Duniho said:
Why do you want the path in a specific format? If you are trying to use
that path to assemble a new path, just use the Path.Combine() method.
.NET will take care of putting any necessary directory separators in there
for you.

You can in fact also get the Path class to normalize the path, putting the
last separator on the string. But it's usually not actually necessary to
do so.

Hi Peter,

I does not work.
Here's what I am trying to do. I would like to remove the @"\".

if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
listBox1.Items.Clear();
string[] fileList = Directory.GetFiles(folderBrowserDialog1.SelectedPath +
@"\", "*.txt");
foreach (string myFile in fileList)
{
listBox1.Items.Add(Path.GetFileName(myFile));
}
}


Jacques
 
W

Wyrm

"Peter Duniho" <[email protected]> a écrit dans le message deop.uzivi1n3vmc__BEGIN_MASK_n#[email protected]...




Why do you want the path in a specific format?  If you are trying to use
that path to assemble a new path, just use the Path.Combine() method.
.NET will take care of putting any necessary directory separators in there
for you.
You can in fact also get the Path class to normalize the path, putting the
last separator on the string.  But it's usually not actually necessary to
do so.

Hi Peter,

I does not work.
Here's what I am trying to do. I would like to remove the   @"\".

if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
  listBox1.Items.Clear();
  string[] fileList = Directory.GetFiles(folderBrowserDialog1.SelectedPath +
@"\", "*.txt");
  foreach (string myFile in fileList)
   {
      listBox1.Items.Add(Path.GetFileName(myFile));
   }

}

Jacques- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

Hello...

Say, did you ever just try and remove it?
Directory.GetFiles works just right in my tests without the trailing
slash.
I can't see your problem here.
 
J

Julia M

I does not work.

Hm.... Freud? ;-)
Here's what I am trying to do. I would like to remove the   @"\".

Why?
Windows doesn't really care if you feed it "C:\" or "C:\\".
If you strip off the path anyway it does not matter.

Otherwise you might want to try

string mypath=Path.Combine(folderBrowserDialog1.SelectedPath, @"
").Trim();
string[] fileList = Directory.GetFiles( mypath, "*.txt");

HTH
 
P

Peter Duniho

[...]
Why do you want the path in a specific format? If you are trying to use
that path to assemble a new path, just use the Path.Combine() method.
.NET will take care of putting any necessary directory separators in
there
for you.

[...]
I does not work.
Huh?

Here's what I am trying to do. I would like to remove the @"\".

Then don't add it in the first place.
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
listBox1.Items.Clear();
string[] fileList =
Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.txt");

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top