cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Move files to folder based on filename

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

 

 

 

 

 

17 REPLIES 17

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.

 

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

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.

 

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

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?

Hi @murrayjl03 ,

 

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

 

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

Hi @trice602 ,

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

Thanks,

Jess

Ok, thanks for sharing.  brb.

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn
WillSG
Resolver III
Resolver III

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

Hi @murrayjl03 ,

 

This works in my test in Desktop.

 

trice602_0-1707238181107.png

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

@trice602 

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

murrayjl03_1-1707240976675.png

 

Hi @murrayjl03 ,

 

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

 

trice602_0-1707241458263.png

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

The error is that you are using the variable %NewVar%, instead, use the variable output out of the action Create %NewFolder%

 

So, in the destination folder you only need to use the previous variable %NewFolder%

 

 

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

@trice602 @WillSG 

Thanks - so this is what I have now:

murrayjl03_1-1707244592626.png



It runs without errors however the folders are created in the 'unstructured' folder rather than 'structured' folder. Any ideas?

Structured:

murrayjl03_2-1707244651546.png

 


Unstuctured: 

murrayjl03_3-1707244689245.png

 

Hi @murrayjl03 ,

 

Please review your step 6 compared to my step 6.  Save. Retest. Mark a solution.

 

trice602_0-1707245208144.png

 

If this was helpful: Please mark as a solution Give me a thumbs up Always glad to help, Tom! Connect on LinkedIn

Ok, use the following variable in the split action %CurrentItem.Name%

 

This will fix the output. See the final process below

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 130154.png

Hi @trice602 

When I do this, I get the following error:

murrayjl03_0-1707246094893.png


I think its because my NewVar isnt working correctly, as mine shows the full path still but yours only shows the folder:

murrayjl03_1-1707246149429.png

 

Do you have %NewVar% in the circled part below in your Create Folder?  If so, you shouldn't.  Change it back to %NewFolder%.

MichaelAnnis_0-1707252517495.png

 

Then, in Move Files, just use %NewFolder% as the folder to move it to.

 

Good luck!

----
If my post has answered your question, please thumbs up and mark this post as a solution.

I also offer paid consulting services at www.peakdigitran.com/appointments and you can find me on LinkedIn at https://www.linkedin.com/in/michael-annis-80903/,
Agnius
Most Valuable Professional
Most Valuable Professional

If your %NewVar% has the full path, then simply use %NewVar% as the destination folder, without providing the rest of the path there. It's as simple as that.

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,176)