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)
ppr
(Peter)
August 3, 2022, 10:22am
3
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
ppr
(Peter)
August 3, 2022, 10:51am
7
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
ppr
(Peter)
August 3, 2022, 11:40am
9
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
ppr
(Peter)
August 3, 2022, 12:54pm
11
so let us know the value of StrTestLocation
sarathi125
(Parthasarathi)
August 3, 2022, 12:56pm
12
@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
ppr
(Peter)
August 3, 2022, 1:00pm
15
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
sarathi125
(Parthasarathi)
August 3, 2022, 1:11pm
17
@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”)
ppr
(Peter)
August 3, 2022, 2:14pm
18
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.
Basic Usage
System.IO.Directory
Directory offers some static methods for basic operations on folder and subfolders
arrFullFilePaths | String() = Directory.GetFiles("C:\_demo\FileSystem\SubfolderA")
Visuals [grafik]
[grafik]
[grafik]
System.IO.DirectoryInfo
The DirectoryInfo class offers instance metho…