web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get exact name of subf...
Power Automate
Answered

Get exact name of subfolder/file

(0) ShareShare
ReportReport
Posted on by 10

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. 

I have the same question (0)
  • Verified answer
    Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    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 Profile Picture
    10 on at

    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 Profile Picture
    2,021 Super User 2024 Season 1 on at

    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 Profile Picture
    10 on at

    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 Profile Picture
    2,021 Super User 2024 Season 1 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 223

#2
David_MA Profile Picture

David_MA 210 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 175

Last 30 days Overall leaderboard