cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Untik
Frequent Visitor

Get exact name of subfolder/file

Hi all,

 

I created 2 lists. List a - Subfolders, b - files in format .txt

I want to compare the names of subfolders and names of files and is they are the same, do some actions. 

 

To get a list "a" I running "Get Subfolders if folder" and the output is "c:/user/etc/etc/etc/etc/folder name"
e.g. C:/User/folder 1/folder 2/folder 3/testfolder

To get a list "b" I running "Get files in folder" and the output is "c:/user/etc2/etc2/etc2/etc2/file name.txt

e.g. C:/User/folder 1/folder 4/folder 5/folder 6/testfolder.txt

Then I will compare them via 2 "for each".

 

How I can get the exact folder name and file name without a path? (in this example name will be a "testfolder") 

Because now it's comparing the whole path, where I need only names. 

1 ACCEPTED SOLUTION

Accepted Solutions
Henrik_M
Dual Super User
Dual Super User

The text representation of a folder variable is its full name, but you can access the short name by adding .Name in the variable call.

 

Try pasting the following into your flow and run it, and see if it explains:

 

Folder.GetSpecialFolder SpecialFolder: Folder.SpecialFolder.DesktopDirectory SpecialFolderPath=> SpecialFolderPath
Folder.GetSubfolders Folder: SpecialFolderPath FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Folders
Variables.CreateNewList List=> List_Folders_NameOnly
LOOP FOREACH CurrentItem IN Folders
    Variables.AddItemToList Item: CurrentItem.Name List: List_Folders_NameOnly NewList=> List_Folders_NameOnly
END

 

You can also use %CurrentItem.Name% in your comparison step, instead of making a dedicated list of the folder names.

View solution in original post

5 REPLIES 5
Henrik_M
Dual Super User
Dual Super User

The text representation of a folder variable is its full name, but you can access the short name by adding .Name in the variable call.

 

Try pasting the following into your flow and run it, and see if it explains:

 

Folder.GetSpecialFolder SpecialFolder: Folder.SpecialFolder.DesktopDirectory SpecialFolderPath=> SpecialFolderPath
Folder.GetSubfolders Folder: SpecialFolderPath FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Folders
Variables.CreateNewList List=> List_Folders_NameOnly
LOOP FOREACH CurrentItem IN Folders
    Variables.AddItemToList Item: CurrentItem.Name List: List_Folders_NameOnly NewList=> List_Folders_NameOnly
END

 

You can also use %CurrentItem.Name% in your comparison step, instead of making a dedicated list of the folder names.

Untik
Frequent Visitor

Thanks for a quick response, but am new to PAD, so struggle to understand, where should I use this code? 
e.g. what I have. 

Untik_1-1615998593884.png

 

the output:

Untik_0-1615998571442.png

 

Where I need output:

  • someotherdata
  • dataone

 

Henrik_M
Dual Super User
Dual Super User

You just CTRL+C copy the code text and CTRL+V paste it where you normally put your actions.

 

I don't understand your intention well enough to give you better advice 😱

Untik
Frequent Visitor

Compare folder name with a file name. 

Actually that's working with subfolders names and file name. 

 

By any chance do you know how to get a filename without an extension? right now I getting filename.gvf

Of course, I can split and then remove an index 1. But maybe there is a simpler way. 

Before your help, I got it working with this Frankenstein, but now I can make it clean and simple. Thank you! 

Henrik_M
Dual Super User
Dual Super User

Just like you are able to use .Name with Folder variables, File variables have some useful properties. You can find an overview here: Datatype properties - Power Automate | Microsoft Docs

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (2,450)