How to Use File Names to Create Year and Month Folders in Power Automate
Question details
The user needs to construct a flow that automatically reads date patterns from file names, extracts the month and year, dynamically creates corresponding folders, and moves files from a shared drive to SharePoint.

- Product
- Power Automate
- Device & OS
- not provided
- Scenario
- Automating document organization by transferring files to specific SharePoint directories based on the date embedded in their file names.
- Observed behavior
- Files must be accurately parsed, previous month/year calculated if necessary, and properly categorized into dynamically generated SharePoint folders.
Verify that your Microsoft 365 account has the required permissions to access the source shared drive, create folders in the destination SharePoint site, and build premium or standard flows in Power Automate.
Create a Power Automate Flow to Parse Names and Route Files
Use built-in Power Automate string expressions to extract the date from the file name, calculate the destination folder structure, and automatically move the files to SharePoint.
Power Automate can dynamically read strings like 'Rack_PFR_##_DD_MMM_YYYY' using split or substring functions. Once extracted, you can format these strings into a valid folder path.
Create an 'Automated cloud flow' triggered by 'When a file is created' (or modified) in your designated shared drive folder.
Add a 'Compose' action. Use the `split()` expression to separate the file name by its underscores. For example, use `split(triggerOutputs()?['body/Name'], '_')` to isolate the Day, Month, and Year segments from the array.
Add another 'Compose' action to concatenate the extracted year and month variables into a folder path. If you specifically need the previous month, use the `addToTime()` expression coupled with `formatDateTime()`.
Add the SharePoint 'Create new folder' action. Set the Site Address and List/Library, then insert the dynamic output from your previous Compose action into the 'Folder Path' field. (Power Automate will automatically create it if it doesn't exist without failing if it already does).
Add the 'Move file' or 'Copy file' action. Select your source file identifier, set the SharePoint site as the destination, and map the destination folder to the dynamically generated path.

Manage Your Organized Files Effortlessly with WPS Office
While Power Automate handles routing and organizing your files across SharePoint, you still need a fast, reliable office suite to view, edit, and collaborate on those documents. WPS Office is a completely free, highly compatible alternative to Microsoft Office that easily handles all your daily document needs.
- 1. Download and Install: Get the free WPS Office installer directly from the official WPS website and complete the quick installation process.
- 2. Access Organized Documents: Open the files you synced to your local drive or downloaded from SharePoint directly in WPS Writer, Spreadsheet, or Presentation.
- 3. Edit and Save Seamlessly: Edit your documents with professional formatting tools and save them back in their native formats without compatibility issues.

Frequently Asked Questions
How do I extract a specific part of a file name in Power Automate?
You can use the `split()` function to divide the file name based on a specific delimiter (like an underscore or space), then specify the array index in brackets (e.g., `[2]`) to pull out the exact text segment you need.
Will 'Create new folder' fail if the folder already exists in SharePoint?
No. The SharePoint 'Create new folder' action in Power Automate is designed to handle this gracefully. If the folder already exists, the flow simply bypasses creating a duplicate and returns the existing folder's metadata.
How do I calculate the previous month automatically in my flow?
You can use the expression `addToTime(utcNow(), -1, 'Month')`. Combine it with the `formatDateTime()` function to format the output as a two-digit month (MM) or full month name (MMMM) depending on your folder naming convention.




