How to get directory of the particular file

Input
Strpath-Documents/database/datatable1/test.xlsx
Output:
Documents/database

If i use path.getdirectory(strpath)
My output is Documents/database/datatable1
My output should be Documents/database
Suggest me

Hi @Demo_User

can you give a try with
strInputPath type string =

Path.GetDirectoryName(Path.GetDirectoryName("Documents/database/datatable1/test.xlsx"))

strResultPath type String =

strInputPath.Split({"\"c}, StringSplitOptions.RemoveEmptyEntries)(0) + "/" + strInputPath.Split({"\"c}, StringSplitOptions.RemoveEmptyEntries)(1)

image

Regards @Demo_User

Documents/database/datatable1 is the correct path to that file.

If you do path.getdirectory(“Documents\database\datatable1”) then you’ll get the path to datatable1 which is “Documents\database”

All you need to do is path.getdirectoryname(“Documents\database\datatable1”) to get the parent folder for datatable1.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.