0

I have a text file inside a drive. Probably inside a folder in the drive. I know the filename and drive name. I searches the file occurance through

var file = Directory.GetFiles(ftpPath,fileName,SearchOption.AllDirectories);

That is ok. But if the file is in a folder under the drive how could I get the ne path in ftpPath variable?

I could not find any valid solution for this.

2
  • Have you seen this post. Seems like they are doing the same thing. Commented Aug 7, 2013 at 15:00
  • I have the Drive. I just need the full path if its under a folder. They are talking about filename Commented Aug 7, 2013 at 15:02

2 Answers 2

1

It should be something like:

ftpPath = Path.GetDirectoryName(file[0]);

Now the path in which filename was found in is stored in ftpPath. Of course you should add some checks before accessing file to ensure it was actually found...

Sign up to request clarification or add additional context in comments.

Comments

0

To parse the path of a path + filename string use:

System.IO.Path.GetDirectoryName(ftpPath);

ftpPath = @"C:\Path\To\The\File\Filename.dll";
will output @"C:\Path\To\The\File"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.