0

How to remove the last two directories ?

D:\11\PayrollSystem\PayrollSystem\bin\Debug\JCMPayrollSystem.accdb

Then the output should be:

D:\11\PayrollSystem\PayrollSystem\JCMPayrollSystem.accdb

need help

John Cris Mañabo
  • 230
  • 1
  • 3
  • 24
  • 1
    what is the context? do you mean during a build in visual studio? are you running a separate application? what have you tried? Also, why do you want to move this file or files? – Brett Caswell Mar 21 '19 at 04:04
  • 1
    Can you please show the working code that you have tried. Quick way would be just to split the string on backslashes and then remove the 2,3 element from the end. As I said quick, might not work for a lot of cases though. – peeyush singh Mar 21 '19 at 04:10
  • Use the `System.IO.Path` class. See marked duplicate for an example. `GetFileName()` will give you the file name. `GetDirectoryName()` will give you the path without the file name. Calling it iteratively will remove successive directories. – Peter Duniho Mar 21 '19 at 04:12
  • I used Path.GetFullPath(fileName), but the problem is I got output in the above question – John Cris Mañabo Mar 21 '19 at 05:20
  • newpath = oldpath.Replace(@"\bin\debug",""); – TaW Mar 21 '19 at 09:45

0 Answers0