web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Move File To Right Folder
Power Automate
Answered

Move File To Right Folder

(0) ShareShare
ReportReport
Posted on by 32

I'm a new to PAD and trying to setup a process to move files.

I have files named as:  123 acb, 456 xyz, 678 kus  and folders named 123, 456, 789
How can I automatically move those files to right folder with the name?

Thanks a lot

@Michael 

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at
    • Set Variable:  %MainFolderPath%
    • Get Files to %Files%
    • For each %CurrentItem% in %Files%
      • Split Text %CurrentItem.Name% by Standard Space (1 time) to %FolderName%
      • Move %CurrentItem% to %MainFolderPath%\%FolderName%
    • End For Each

     

    Best of Luck!

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Sorry...one technicality missing here.  Split text is going to go to a list of text.  Each Text on a separate row.  You can decide what to call the variable, let's call it %ListText%.  So, after Split Text, you need:

     

    Set Variable %FolderName% to %ListText[0]%

     

    This will return the first text in that list which will be those 3 folder numbers that occurred before the "space" delimiter.

  • Kyle7989 Profile Picture
    32 on at

    Thanks Michael. 

    I am trying to understand your instruction, but I can not.

    Maybe I skipped some steps. I need to start all over again.

    Do you have any document or video to learn PAD from zero?

    Thank you so much for your time and wish you all the best.

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @Kyle7989 

     

    Below is a working example flow of your scenario.

     

    shindomo_0-1632477713140.png

     

    Yon can copy & paste below code snippet to your Flow Designer window.

     

     

     

    SET BaseFolderPath TO $'''C:\\Users\\User01\\Documents\\Move File To Right Folder'''
    Folder.GetFiles Folder: BaseFolderPath FileFilter: $'''*.txt''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP FOREACH CurrentItem IN Files
     Text.Split Text: CurrentItem.Name StandardDelimiter: Text.StandardDelimiter.Space DelimiterTimes: 1 Result=> TextList
     SET TargetFolder TO $'''%BaseFolderPath%\\%TextList[0]%'''
     File.Move Files: CurrentItem.FullName Destination: TargetFolder IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
     Display.ShowMessage Title: $'''File Moved''' Message: $'''[Source]
    %CurrentItem.FullName%
    
    [Destination]
    %TargetFolder%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    END

     

     

     

    The result of running the above flow is as follows:

     

    [BEFORE]

    C:\USERS\USER01\DOCUMENTS\MOVE FILE TO RIGHT FOLDER
    │ 123 acb.txt
    │ 456 xyz.txt
    │ 789 kus.txt
    │
    ├─123
    ├─456
    └─789

     

    [AFTER]

    C:\USERS\USER01\DOCUMENTS\MOVE FILE TO RIGHT FOLDER
    ├─123
    │ 123 acb.txt
    │
    ├─456
    │ 456 xyz.txt
    │
    └─789
    789 kus.txt

     

    Thank you.

  • Kyle7989 Profile Picture
    32 on at

    @Anonymous  It WORKS. I can't understand your code but it WORKS

    So nice of you. Thank you so much.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 780

#2
Valantis Profile Picture

Valantis 668

#3
Haque Profile Picture

Haque 601

Last 30 days Overall leaderboard