Getting Name of subfolder

Hi,

I have a path like : \xxx\Client\Ireland\Dublin\Policies\AAA\Joe Bloggs\Policy\Text.pdf

I want to just get the name of the last directory Policy to write it into an excel in a column.

How can I just get the name of the last sub folder of a file?

@Sean_Ryan1

use →

Environment.CurrentDirectory.Split("\"c).Last

and also try this->

path.GetDirectoryName(Input_Path as String)

Sticking to FileSystem API instead of String Methods:
grafik

The first line Environment … just returns the word getfiles

When I use this it is printing the Dublin Directory

share what you have done so far. As the screenshots are done within the imediate panel in UiPath so we can see Policy directory

Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum


just set a break point on relevant location, degung and get paused

type in the statements, test variables … within the immediate panel and show us what was the input, which methods were used and what was returned

New FileInfo(StrTestLocation).Directory.Name

This is the code I’m currently using to try and print it. The StrTestLocation is a variable that contains the path of the main directory.
As I stated above its providing the directory previous to my main location as oppose to the directory associated with each file down through all sub folders

so let us know the value of StrTestLocation

@Sean_Ryan1 ,

Try like this,

Path.GetFileName( Path.GetDirectoryName("\xxx\Client\Ireland\Dublin\Policies\AAA\Joe Bloggs\Policy\Text.pdf"))

It is: \ax02\clients\Ireland\Dublin\Policies

Under this Directory Policies I am pulling every file in it and in all of its sub directories. After Policies there are numerous sub directories

I can’t go this high of a level with the path as there are many sub folders under Policy that I am pulling files from

As this is a folder path instead of a filepath you are interested on the last folder name (different scenario)

grafik

Yes but what about the files in sub folders after Policies that get picked up. I want to be able to print their lowest level of sub folder

@Sean_Ryan1,

So whatever the file your picking pass that path here, then you will get the final folder path.

Path.GetFileName( Path.GetDirectoryName(“yourFilePath”)

Just let’s sort it out one by one
as mentioned in the beginning:

  • Input: A FullFilePath - needed output: the FolderName containing the file

\xxx\Client\Ireland\Dublin\Policies\AAA\Joe Bloggs\Policy\Text.pdf - Policy

then as mentioned use the FullFilePath and take the FolderName from the Folder containing this File

So, Implementation is as given above

But let’s not mixed up FullFolderPaths and FullFilePath

Kindly note: Any Logics like the file is detectable on pattern name Dot Extension are not valid:

grafik


as we are looking for files with GetFiles then IAmAFolder.xlsx is not part of the retrieval