The solution is to:
- Extract the first 5 digits from the source folder name
- Find the destination folder that starts with the same 5 digits
- Move the source folder into that matching destination folder
The problem usually happens because:
- The variable contains more or less than the 5 digits
- The comparison is exact match instead of “starts with”
- The folder list is not filtered correctly
This can be solved using string functions and proper matching logic.
You have this structure:
Source Folders:
12345
23456
34567
Destination Folders:
12345_ProjectA
23456_ProjectB
34567_ProjectC
And you want the result to be:
12345_ProjectA
└─ 12345
23456_ProjectB
└─ 23456
34567_ProjectC
└─ 34567
The key idea: Match folders by the first 5 digits, not the full name.
How to do it (high‑level steps)
General logic (works for Power Automate, PowerShell, scripts)
- Get the source folder name (12345)
- Store the 5‑digit number in a variable
- Loop through destination folders
- Check: Does the destination folder name start with the same 5 digits?
- If yes > move the source folder
Key expressions:
Get first 5 characters:
substring(variables('SourceFolderName'), 0, 5)
Check if destination folder starts with that number:
startsWith(destinationFolderName, fiveDigitNumber)
This avoids variable mismatch issues.
✅ If this answer helped resolve your issue, please mark it as Accepted so it can help others with the same problem.
👍 Feel free to Like the post if you found it useful.