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 alphab...
Power Automate
Unanswered

Moving files to alphabetical folders

(0) ShareShare
ReportReport
Posted on by 15

Hi,

 

I'm trying to get Power Automate to move newly added files to its respective alphabetical folders. Any file names that start with an "A" will be moved automatically to folder "A", any file names that start with a "B" will be moved automatically to folder "B", and so on until "Z".

 

Example:

axxxxxxx.pdf -> move to folder A

axxxx01.pdf -> move to folder A

hxxioiu01.pdf -> move to folder h

 

Does anyone have an idea how can this be done?

 

Kind regards,

Chris

 

Categories:
I have the same question (0)
  • Sundeep_Malik Profile Picture
    6,484 on at

    Hey @iZz0 

     

    You can use substring to extract the first letter of the file.

     

    Something like this:

    Expression used:

     

    substring(outputs('Compose'),0,1)

     

    Sundeep_Malik_0-1669192928683.png

    Then after this I will provide you a technique which is not the best, but that was only I could think of:

    You can use a switch action for this, if the compose 2 has A, move the file to Folder A, if it has B, move to Folder B, and respectively for all. 

    Sundeep_Malik_1-1669193105557.png

     

    Again I will say there could be better methods.

     

    @Pstork1 @grantjenkins 

    Any other solution?

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Agree substring to get the first letter. But would then add that letter to the end of the path the file will be moved to, rather than a Switch. Below would move the file into a subfolder with the letter.

    grantjenkins_0-1669204486717.png

     

  • Pstork1 Profile Picture
    68,693 Most Valuable Professional on at

    Yes, I would use a switch and extract the first character.  The only other things to add are that you should cast the character to uppercase or lowercase since switch is case sensitive. Also, you may run out of cases before you get to 26 letters.  If you do then just add a default that contains another switch and pick up from where you left off on that switch.

  • Pstork1 Profile Picture
    68,693 Most Valuable Professional on at

    That would work as well assuming the folder names are just a single letter.  That also wouldn't handle files where the first letter wasn't a-z.  So you would need to make some provision for that.

  • iZz0 Profile Picture
    15 on at

    Thank you so much all three of you champions, I will give it a go today. Forgot to mention that this is for Windows network drive, but it should be similar flow as mentioned above.  At least I can have some ideas how to implement this, And yes, the folder names just a single letter.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    @iZz0 With my original solution @Pstork1 made a good point about if the files didn't start with a letter, then what would happen.

     

    I'd likely cater for this by firstly creating a folder in your network drive that would hold files that didn't start with a letter. Then in my flow, add another Move file action after the first one but configure it to run ONLY if the first action failed. In my example I'm still just using SharePoint as the destination but same concept.

     

    grantjenkins_0-1669252108095.png

     

    If the Move file A-Z was successful, then we can assume the file started with a letter and the flow would complete. However, if it failed then we would want to move the file into a different folder. On Move file Other I've set the action's Configure run after, then set it to has failed so it will only run if the first action failed.

     

    grantjenkins_1-1669252336592.png

     

    grantjenkins_2-1669252361195.png

     

    And finally, the Terminate set to Successful will ensure our flow still shows as successful and not failed.

  • iZz0 Profile Picture
    15 on at

    Hi,

     

    Windows File Server doesn't have a move files, so I had to do a Copy File and then Delete File afterwards. Below is what I attempted, but it's failing in the third step (Copy File). As it seems like it doesnt seem like it recognises '\'?

     

    in my mind xxxx\Attachment\Parked\A

    But Power Automate interpret it as xxxx\Attachment\Parked/A and hence it couldn't find the folder path.

     

    I have tried \Outputs, \\Outputs, /Outputs to no avail. Do you know what I can use for "\"?

     

    iZz0_0-1669262329652.png

     

    Many thanks,

    Chris

     

  • iZz0 Profile Picture
    15 on at

    Hi Gents,

     

    I managed to get it working, the error is to do with the gateway that I had. Else, the advice that you all gave worked perfectly. Thank you very much!

     

    Cheers,

    Chris

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

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard