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
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
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…
ok got it, Thanks alot
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.