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

Notifications

Announcements

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
 
I have the same question (0)
  • Verified answer
    VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard