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?
and also try this->
path.GetDirectoryName(Input_Path as String)
Sticking to FileSystem API instead of String Methods:
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
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
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)
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
So whatever the file your picking pass that path here, then you will get the final folder path.
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:
as we are looking for files with GetFiles then IAmAFolder.xlsx is not part of the retrieval
This CheatSheet introduces the basic use of available functionalities provided by the .Net API in order to deal with the filesystem. With further examples also special cases are presented.
Directory offers some static methods for basic operations on folder and subfolders
arrFullFilePaths | String() = Directory.GetFiles("C:\_demo\FileSystem\SubfolderA")
The DirectoryInfo class offers instance metho…