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 / Set a variable with th...
Power Automate
Answered

Set a variable with the name of the most recent file in a folder

(0) ShareShare
ReportReport
Posted on by 12

I want to run "Get Files in Folder" the sort by "Date Created" or "Last Modified" to get the most recent file in a folder.

 

In the list it creates the filename I am looking for is always at Index 0. Can I pass "Index 0" to another variable or delete all other indexes except 0?

 

I have another process the run weekly to create this file and drop it in a specific fold. The folder fills up with many file with their names auto-generate with the date inserted in to the file name.

 

This may not be the correct way to get this information I need but here is what I'm trying to do.....

I'm trying to set a variable with the name of the most recent file in a folder so I can pass it to another Flow.

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    %Files[0]%

  • Verified answer
    VJR Profile Picture
    7,635 on at

    After the "Get Files in Folder" set a variable to the 0th index of the Files Datatable.

    Now you can make use of the "MostRecentFile" variable.

     

    VJR_0-1648783002642.png

     

  • Verified answer
    Riyaz_riz11 Profile Picture
    4,214 Super User 2026 Season 1 on at

    Hi @PapaOssis ,

     

    You can try this.

    %Files[0]%

    If you required full name

    %Files[0].FullName%

     

    Regards

    Ahammad Riyaz

    --------------------------------------------------------------------------------
    If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

  • PapaOssis Profile Picture
    12 on at

    THANK YOU!!!

     

    That works as expected!!!!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    But if we use Get Files in Folder in ForEach loop, it can't be iterated. I want to rename a file in every loop.

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 227

#2
David_MA Profile Picture

David_MA 204 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 177

Last 30 days Overall leaderboard