Split a Folder Path and File Name

15.2k views Asked by At

I have a Folder Path and file Name which I want to split it. The two paths are : F:\AutoImport - Folder\20141612\Inv.trg and F:\EmailImport\[email protected]_01-01-2014_05-05-22\Inv.trg.

So I want to split this path and also I just want "Rohan" name and "20141612" from the path. Please suggest how can I achieve this in .net using C# coding.

This Name is needed to be used as a Custom Name in Kofax Capture Batch Name. As of Now the Batch Name is: 45- F:\EmailImport\[email protected]_09-01-2014_10-02-30\New Text Document.trg. I also don't know from where 45- came and this Batch name is coming from a Sample script giving by Kofax.

1

There are 1 answers

0
Chandan Kumar On BEST ANSWER

Here is your output. By using String.Split() you can easily achieve this :

string filepath1 = @"F:\EmailImport\[email protected]_01-01-2014_05-05-22\Inv.trg";
System.IO.FileInfo fif = new System.IO.FileInfo(filepath1);
string folderdet = fif.Directory.Name;
string[] arr1 = folderdet.Split('@');
string myname = arr1[0];
Console.WriteLine(myname);

string filepath2 = @" F:\AutoImport - Folder\20141612\Inv.trg";
System.IO.FileInfo fileinfo = new System.IO.FileInfo(filepath2);
string foldername = fileinfo.Directory.Name;
Console.WriteLine(foldername);

Check it and let me know if you have any issues.