Getting the Directory Name

Hi i need to fetch only the directory name from a path like C:\Users\abc\Documents\UIPATH\Project1\datareport
datareport is the folder and i want to get only folder name

1 Like

Hi @Tel43,

You can iterate on the following path like,

for each folder in Directory.GetDirectories(Path)
{
Path.GetFileNameWithoutExtension(folder)
}

Let me know in case of further queries…
Thanks :slight_smile:

2 Likes

yes it worked,but why is it giving me the folder name?
although it specifies GetFileNameWithoutExtension

Actually, we are iterating on the folders only, and passing the folder path in the loop…

So its giving the folder name only to you…

1 Like

ok got it, Thanks alot

1 Like

assign strArray = path.GetDirectoryName(FileNameWithPath).Split("\"c)
assign foldername = strArray(strarray.length)

The first assign activity will get you everything from C:\ all the way up to “datareport”. Then split the result with \ and you will get a string array.
With the second assign, you get the last item in the array. This will be “datareport” in your case. Hope that helps.