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 / How to get only latest...
Power Automate
Answered

How to get only latest or new file added in folder

(1) ShareShare
ReportReport
Posted on by 22
Hi, 

I have folder that only images are in jpg format. each week every Monday image will be add in that folder. so i want only latest image file and newly added image in that folder.
 
i use get files in folder action, i sort there according to creation time and last modified, but it's not work
get files in folder action produce the variable like files, in that variable multiple files are present
 
i want latest file added in folder, i used files[0], i got the file but it's not latest file added in folder. 
 
please guide me how to use this or any other action present in power automate desktop
 
  • Verified answer
    VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at
     
    Please find the solutions.
     
    1. Native get files in folder method.
    Please copy the below code to you flow and change the path.
     
    Code:
     
    Folder.GetFiles Folder: $'''C:\\Users\\Downloads''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.CreationTime SortDescending1: True SortBy2: Folder.SortBy.CreationTime SortDescending2: True SortBy3: Folder.SortBy.CreationTime SortDescending3: True Files=> Downloaded_Files
    Display.ShowMessageDialog.ShowMessage Message: Downloaded_Files[0].FullName Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed4
    
    2. Use Powershell script to get all the files path that are created on Current Day.
    Please copy the below code to you flow and change the path.
     
    Code:
    @@copilotGeneratedAction: 'True'
    Scripting.RunPowershellScript.RunPowershellScript Script: $'''# Powershell script to get latest files only i mean today created files from the C:\\Users\\Downloads folder
    $downloadsPath = \"C:\\Users\\Downloads\"
    $today = (Get-Date).Date
    $latestFiles = Get-ChildItem $downloadsPath -Recurse | Where-Object { $_.CreationTime -ge $today }
    foreach ($file in $latestFiles) {
        Write-Host \"File: $($file.FullName) - Created: $($file.CreationTime)\"
    }''' ScriptOutput=> PowershellOutput ScriptError=> ScriptError
    
     
    (Note:- if you got your solution you can mark as solution and gives kudos)
     
    Thanks & Regards
    Vishnu Reddy

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

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 414

#2
11manish Profile Picture

11manish 331 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard