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

Moving Files to Folders According to Months

(0) ShareShare
ReportReport
Posted on by 14

Hi All,

I have been trying to figure out a way on how to move files with dates included in the names into folders that is based on their months but not much progression in P.A.D.

I'm currently working with renamed excel files fyi.

Any kind soul knows the work around for such issue? 

I have the same question (0)
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    The high level flow would look more or less like this:

    1. Get files in folder with a filter for *.xls* files
    2. For each loop on the list of files generated by Get files in folder
      1. Parse text on the %CurrentItem.NameWithoutExtension% (where %CurrentItem% is the variable generated by the For each loop), using regular expressions to retrieve the date
      2. Convert text to date time using the %Match% from the Parse text action
      3. Get sub-folders in folder using the %TextAsDateTime.Month% as the filter (assuming your folders are named with the month name; alternatively you might need to use Convert date time to text to convert the date to a preferred format that matches your folder naming convention)
      4. Move file(s) to move %CurrentItem% to %Folders[0]% (the first folder in the list retrieved by Get sub-folders in folder)

    To give you a more detailed explanation on how to parse the file name and how to find the specific folder, I would need more details on how your files and folders are named.

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

    If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/

  • GoldenShell Profile Picture
    14 on at

    Hi Agnius,

    For a more detailed explanation, my files are labelled as '**** 14 Jul 23.xlsm'.

    My folders, for example are labelled as 'Jul 23'.  My folders are formatted in 'mmm YY'  format. 

    I would want P.A.D to automatically rename the files as the format stated above ^, then moving those renamed files into their respective month folders.

    The renamed files are downloaded on a daily basis too so it will appear under my 'Downloads' folder in PC with no issue.

    Really appreciate your prompt response & assistance! 🙂

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

    Okay, the way I read it is that you also want to rename your files to also include a date in the file name. And I make a bold assumption here, that the date to be added to the file name is the current date.

     

    If that is the case, the following flow will do the trick:

    Agnius_0-1689332229191.png

    What it does is as follows:

    1. Gets the current date
    2. Formats it according to your folder naming
    3. Checks if a folder like that exists in the target directory:
      1. If it doesn't - creates the folder
    4. Gets the files in the input directory
    5. For each file:
      1. Moves it to the target directory (which now includes the date folder)
      2. Renames the file adding the current date in the format of 'dd MMM yy' to the file name

    Here's a snippet that you can copy and paste directly to PAD to have those actions created for you:

    SET InputDirectory TO $'''C:\\Users\\agnius\\Downloads'''
    SET TargetDirectory TO $'''C:\\RPA'''
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''MMM yy''' Result=> FolderName
    IF (Folder.IfFolderExists.DoesNotExist Path: $'''%TargetDirectory%\\%FolderName%''') THEN
     Folder.Create FolderPath: TargetDirectory FolderName: FolderName Folder=> TargetDirectory
    ELSE
     SET TargetDirectory TO $'''%TargetDirectory%\\%FolderName%'''
    END
    Folder.GetFiles Folder: InputDirectory FileFilter: $'''*.xlsm''' 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 CurrentFile IN Files
     File.Move Files: CurrentFile Destination: TargetDirectory IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
     File.RenameFiles.RenameAddDateOrTime Files: MovedFiles[0] DateTimeToAdd: File.DateTimeToAdd.Current DateTimePosition: File.AddTextPosition.AfterName DateTimeSeparator: File.Separator.Space DateTimeFormat: $'''dd MMM yy''' IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
    END

     

    Note: You will need to change the values for %InputDirectory% and %TargetDirectory% that actually matches your directories. I specifically stored these into variables for easier adjustment.

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

    If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/

     

  • GoldenShell Profile Picture
    14 on at

    Hi Agnius, 

    May I check if the following flow has the capability to move the renamed files according to the respective month folders if it matches? 

    For example if my Excel file has ' *dd* Jul 23' in the naming, will it move into 'Jul 23' Folder accordingly? 

    My Folders have been created beforehand, hence it is just the matching & moving the renamed files that is being downloaded on a daily basis, according to the month folders formatted as 'MMM yy'. 

    Your insight is greatly appreciated. 😅

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    The flow does not check what date the file contains in its name, because it renames the file itself, so by default, it knows what folder to use, as well. It uses the folder for the month of the current date. Regardless of the folder being already created, or not, it will work.

     

    If however, your files already have a date in their file name, and you do not want them to be renamed with the current date, but instead want the flow to check the date in the file name and then move them accordingly, you would need a different flow. But the way I understood your previous requirement was that:

    1. You download the files daily,
    2. You want the files renamed based on the current date,
    3. You want the files moved to a folder based on the current date.

    If that is correct, the flow will work. Try it on some sample files and see.

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

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • GoldenShell Profile Picture
    14 on at

    Will the flow be able to work for sub-folders as well?

    Just realized that the Months' Folders are a sub-folder of another Folder. 

    Looking forward to your response as always!

     

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Well then, you should set the %TargetDirectory% to be the parent folder where the Month Folders reside. It will work fine then.

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

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • GoldenShell Profile Picture
    14 on at

    Managed to use the flow that you have provided with the variables changed!

    Thank you so much, Agnius!

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 796

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 538

Last 30 days Overall leaderboard