@eyarea51
Please follow the below approach:


Before:

After:

Code:
Folder.GetFiles Folder: $'''C:\\Boot\\Images''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
SET Root_Folder TO $'''C:\\Boot\\Images'''
LOOP FOREACH CurrentItem IN Files
SET FileName TO CurrentItem.Name
@@copilotGeneratedAction: 'False'
Scripting.RunPowershellScript.RunPowershellScript Script: $'''# Filename
$filename = \"%FileName%\"
# Regex pattern to match and capture the year and month
$pattern = \'WIN_(\\d{4})(\\d{2})\\d{2}_\\d{2}_\\d{2}_\\d{2}\'
# Use regex to match and extract the year and month
if ($filename -match $pattern) {
$year = $matches[1]
$monthNumber = $matches[2]
# Convert month number to month name
$monthName = [CultureInfo]::CurrentCulture.DateTimeFormat.GetMonthName([int]$monthNumber)
# Output the extracted year and month name
Write-Output \"$year\"
Write-Output \"$monthName\"
} else {
Write-Output \"Filename format does not match the expected pattern.\"
}''' ScriptOutput=> PowershellOutput
IF NotContains(PowershellOutput, $'''Filename format''', True) THEN
Text.SplitText.Split Text: PowershellOutput StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TextList
SET Str_Year TO TextList[0]
SET Str_Month TO TextList[1]
IF (Folder.IfFolderExists.DoesNotExist Path: $'''%Root_Folder%\\%Str_Year%''') THEN
Folder.Create FolderPath: Root_Folder FolderName: Str_Year Folder=> NewFolder
END
IF (Folder.IfFolderExists.DoesNotExist Path: $'''%Root_Folder%\\%Str_Year%\\%Str_Month%''') THEN
Folder.Create FolderPath: $'''%Root_Folder%\\%Str_Year%''' FolderName: Str_Month Folder=> NewFolder
END
File.Move Files: CurrentItem.FullName Destination: $'''%Root_Folder%\\%Str_Year%\\%Str_Month%''' IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
END
END
Please adjust the configuration of the folders specified in the variable to suit your requirements.
How to copy/paste the above code into your power automate desktop?

Thanks,
Deenuji Loganathan 👩💻
Automation Evangelist 🤖
Follow me on LinkedIn 👥
-------------------------------------------------------------------------------------------------------------
If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀