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
Super User
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
Super User
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.

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
Super User
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 😱

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
Super User
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 Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,883)