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 / Moving Files to Folder...
Power Automate
Answered

Moving Files to Folders Based on FileName Contents - MY FLOWS WORKS but is very slow. How would I do this efficiently?

(0) ShareShare
ReportReport
Posted on by 35

Hi There - I am new to PAD and have created a few flows. I am not a trained coder but keen to improve. I created a flow to move a number of named files from a range of subfolders into a different set of folders based on their filename which in each case has a 4 digit SKU.

My flow works and did its process with a text output to match, however it took hours to run and there must only have been about 500 files or less. Can you provide me tips on how I would do this more efficiently?

Ive included the flow in the screenshot with annotation

In sum I:

- get files in folder and put in a list

- get folders and put in a list

- loop through the file list and parse the name looking for folders to match

 

I did try looping through folders thinking there were fewer folders but with files I can remove them from the list as I go. Still clearly I am not doing this the best way.

 

I have the same question (0)
  • VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 on at

    Hi @TTMH ,

    Instead of moving files one by one, explore using the "Move Files" action to move multiple files as shown in below image. This allows you to specify a source and destination folder and move all matching files at once.

     

    Move 2.png

    Note: Further if you have anything just let me know and if it worked mark, it as solution

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @TTMH 

    As suggested by @VishnuReddy1997 this could potentially be one way to optimize from a Power Automate Desktop perspective as its accepting list parameter as well.

     

    However, if you find that it's still not yielding the desired results, you have the option to implement the same functionality using .NET with C# or VB. This alternative approach may offer a result in just a few minutes.

     

    Please let me know if you require any help to writing the code in C# for your use case.

     

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Copy and paste your PAD into GPT and ask it for a command line or powershell script to do the same thing in an array setup as optimized as possible for speed. 

    I had a similar one. 50 files took about 30 seconds moving one by one and it was instantaneous with the powershell script. 

    good luck. 

  • NDAG Profile Picture
    2 on at

    So this may or may not be a solution for you.

    The way I figured going about a similar problem is by using a combination of file-extension matching to first filter the extension I want. Then the second filter using regex checks if the name follows a specific pattern. Check my attached image.

    Hope this helps someone :).

     

    example.jpg

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    This can happen with nested loops. Not a great idea to loop through all folders inside the file loop. Instead, do this:

    1. Loop through folders
    2. Use Get files in folder to get only the files with the current folder name in the file name (instead of using Parse text)
    3. Use Move file(s) to move all the matched files at once in batch.

     

    The following flow would do that for you:

    Agnius_0-1710138652075.png

     

    The only issue with this is the lack of Rename file(s), because the requirement there is not really clear to me. Why and how exactly do you want those files named?

     

    If the above is okay for you, you can copy the following code and paste it directly into your PAD flow designer to get the actions created for you automatically:

    Folder.GetSpecialFolder SpecialFolder: Folder.SpecialFolder.DesktopDirectory SpecialFolderPath=> SpecialFolderPath
    SET OutFolder TO $'''%SpecialFolderPath%\\AI\\04 Photoshop Exports'''
    Folder.GetSubfolders Folder: $'''%SpecialFolderPath%\\AI''' FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> ReceivingFolders
    LOOP FOREACH CurrentFolder IN ReceivingFolders
     Folder.GetFiles Folder: OutFolder FileFilter: $'''%CurrentFolder.Name%*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> FilesToMove
     IF IsNotEmpty(FilesToMove) THEN
     File.Move Files: FilesToMove Destination: CurrentFolder IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
     END
    END
    
  • TTMH Profile Picture
    35 on at

    Thanks - I will look in to this and get back to you.

  • TTMH Profile Picture
    35 on at

    I wasn;t aware this was even an option - thanks I'll give it a go and see how I get on. I appreciate your help

  • TTMH Profile Picture
    35 on at

    Thank you for this - I really appreciate it - i will give it a go and see how I get on.

    The rename files is because I've bulk exported a whole load of image files and they are labelled with a letter as the first character (A,B,C,D etc) and then a SKU (_1234) and then a text string of varying length of the artboard exported. Once moved into a SKU folder I am then stripped out the names so they only have the first character so in each folder I get a uniform list of files A>Q (there is a slight complication of having B2, J2, K2) but I did those manually.

    Its so I can then bulk reference these files with ease from other spreadsheets knowing folder: 1234 contains files labelled - A.jpg, B.jpg etc etc.
     

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