cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
davidcab
Helper I
Helper I

Help to copy only new files

I am just getting started with flows but haven't found an answer to this. my flow gets a list of all png files in a directory then transfers them to a onedrive folder. I want it to run every night BUT only transfer items that are not currently in the onedrive folder. 

 

6 REPLIES 6
MichaelAnnis
Super User
Super User

Do you have the freedom to move those files locally (say to a subfolder called "filed") after they have been filed in OneDrive?

The query of files is all png files from a large share on my server with many subfolders. 

I am copied all files to a personal onedrive for now, might change to sharepoint later, but i want to run this nightly and only pull new files added to the share. 

 

I prefer not to add any new folders on the server share. I can do anything to my onedrive. 

Henrik_M
Super User
Super User

You can tell the action to do nothing if a file exists, which is also the default.

Maybe I'm misunderstanding the challenge...? 🤔

Henrik_M_1-1664911254209.png

 

Henrik has a point, but if it's 1000s of files, you don't want it to have to reject every single one that is not new.  So, here you go:

 

Get files *.png for [ FromAddress and all Subfolders] to %Files% sort by Last Modified descending (newest on top).

Get files *.png for [ToAddress and all Subfolders] to %MyFiles% sort by Last Modified descending (newest on top).

 

Loop Condition While %Files[LoopIndex].Modified% >= %MyFiles[0].Modified% from LoopIndex of 0 to %Files.Count - 1%

    Move %Files[LoopIndex]% to %ToAddress%

End Loop

 

In English, this says as long "Last Modified Date/Time" of the file is later than (or equal to) the "Last Modified Date/Time" of my most recent file, move it, and as soon as it is not, end the loop.  This will stop it from having to do logic on all the files because it will exit the loop as soon as it is done with the "new" files.

 

This can work but ideally i'd like to prevent it from checking all 5000+ files each time. and only check new ones.

I guess i can leave it as is for now. a full run takes under 2 minutes. 

This can work but ideally i'd like to prevent it from checking all 5000+ files each time. and only check new ones.

I guess i can leave it as is for now. a full run takes under 2 minutes. 

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!

Users online (2,440)