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 / Move files to folder b...
Power Automate
Unanswered

Move files to folder based on filename

(1) ShareShare
ReportReport
Posted on by 20

Hey,

I have 1 folder, which contains multiple images in with the format SKU_other_details.jpg.

 

I am wanting to create a flow which will create a folder called the SKU name, and then add all the relevant images into this folder e.g.

1234_test_image_1.jpg

1234_test_image_2.jpg

would all go into a folder called "1234".

 

9876_test_image_1.jpg

9876_test_image_2.jpg

would all go into a folder called "9876". etc.

I am a complete newbie to Power Automate so any help / explainations would be greatly appriciated. 

 

Thanks

 

 

 

 

 

I have the same question (0)
  • trice602 Profile Picture
    15,402 Super User 2025 Season 2 on at

    Hi @murrayjl03 ,

     

    This works in my test, please review the flow.  Please note I am doing this in Power Automate CLOUD and not DESKTOP.  I will typically only use desktop for RPA (and other projects) but as a general rule, my first recommendation and option is cloud.

     

    trice602_0-1707235776200.png

     

    So here I am listing all my files in a folder.  Then for each file, I loop through and get the file content.  Next I split the file name by "_" to isolate the 1234 of the file name.  Then I reference the value I just got (1234) out of the file name.  Lastly, I create the folder and file.  If the folder doesn't exist, it is created.  Works well in testing.  Uses OneDrive but you could also go this in SharePoint with related actions.

     

    So first two actions pretty straight forward.

     

    trice602_1-1707236018343.png

     

     

    Next I split the file name into an array by "_".

     

    trice602_2-1707236070861.png

     

     

    Next I get the file name value "1234" or "9876" out of the array but using the first value which starts with [0].

     

    trice602_3-1707236140594.png

     

     

    The last step is to create the folder and file.  Again, if the folder doesn't exist it gets created.

     

    trice602_4-1707236218424.png

     

     

    This is a helpful flow and can run through thousands of files in a folder and help you organize them into meaningful dynamic folder names.

     

     

  • trice602 Profile Picture
    15,402 Super User 2025 Season 2 on at

    Hi @murrayjl03 ,

     

    If this is your first flow I wanted to share the apply to each or for each loop process.  When you add the action get file content and reference the dynamic content ID from list files in folder, this action will automatically wrap itself in an apply to each or for each loop, so think of it this way... for each file in the folder, do these actions...

     

    trice602_5-1707236447996.png

     

    So after using list files in folder, next add the action get file content and point to the ID of the list files in folder.  You will notice this wraps itself in the loop for you.

     

     

  • murrayjl03 Profile Picture
    20 on at

    Hi @trice602, 

    Thanks so much for taking the time on this! I actually dont have a CLOUD account, only desktop - I dont suppose you have a solution for desktop?

  • trice602 Profile Picture
    15,402 Super User 2025 Season 2 on at

    Hi @murrayjl03 ,

     

    Yes the process is nearly identical in Desktop.  Where are your files stored?  OneDrive, SharePoint, local file, etc?

     

     

  • murrayjl03 Profile Picture
    20 on at

    Hi @trice602 ,

    Currently in Dropbox (so a folder like this: C:\Users\XX\Dropbox\FOLDER) but I can make local if easier.

    Thanks,

    Jess

  • trice602 Profile Picture
    15,402 Super User 2025 Season 2 on at

    Ok, thanks for sharing.  brb.

  • WillSG Profile Picture
    352 Moderator on at

    Hi @murrayjl03   I hope you are doing well.

     

    Here is a simple but effective way to do it (see image below):

     

    1. The first action is getting all the JPG files on the folder.
    2. You must use a For Each Action to work with the previous list created.
    3. In action #3 you use the “_” to split the %CurrentItem% variable.
    4. The Variable %TexList[0]% is the out put from the Split Action, and by using the [0] you will obtain the first value of the Split which would be the SKU number.
    5. Finally, you will create the Folder and move the file/image.

     

    PS: Even though the Create Folder action is used multiple times to create the same folder with the same name, this will not affect the final output that you need.

     

     

    Hope this helps,


    If I have addressed your inquiry successfully, kindly consider marking my response as the preferred solution. If you found my assistance helpful, a 'Thumbs Up' would be greatly appreciated.

     

    Additionally, I offer specialized consultancy and development services leveraging PAD. If you're interested in exploring these services further, feel free to DM me, and we can initiate a discussion.

     

    Kind regards,

     

    -

    Managing Director & Automation Lead

    RAMS CR (Recruitment & Automation)

    LinkedIn Profile

     

    WillSG_Screenshot 2024-02-06 103327.png

  • trice602 Profile Picture
    15,402 Super User 2025 Season 2 on at

    Hi @murrayjl03 ,

     

    This works in my test in Desktop.

     

    trice602_0-1707238181107.png

     

  • murrayjl03 Profile Picture
    20 on at

    @trice602 

    Thanks so much! I gave it a go but have the following error, anything obvious im missing?

    murrayjl03_1-1707240976675.png

     

  • trice602 Profile Picture
    15,402 Super User 2025 Season 2 on at

    Hi @murrayjl03 ,

     

    I think it is just the \ at the end of your path is missing.

     

    trice602_0-1707241458263.png

     

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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard