Hi,
I'm trying to create a PAD flow where I'm moving files to folders.
The foldres should by in a format of YYYYmmm.
The file name have a long name and part of the name is a date (example for a file name:"AC01DA7SBC02__23.01.13-03.43.03_00001.csv"
I want to take the year and month from the file name and check if there is a folder with this name.
To do so I have used a python script as bellow, and I'm checking if the folder exists If it doesn't exist I want to create it.
The problem is that when I'm trying to do it I get a massage that the path is using "Illegal characters in path".
I have tried to add steps which are looking for invisible characters but it didn't help.
When I tried to hard-code the output of the python (2023Jan) it worked.
Can anyone help me?
My Python code:
import re
from datetime import datetime
# Set the file name
file_name = "%FileName%"
# Extract the month from the file name using regular expressions
match = re.search(r"_(\d{2})\.(\d{2})\.", file_name)
year = match.group(1)
month = match.group(2)
# Convert the input string to a datetime object
dt = datetime.strptime(year + month, "%%y%%m")
# Format the datetime object as a string in the desired format and replace illegal characters
foldername = dt.strftime("%%Y%%b").replace('/', '-').replace('\\', '_').strip()
# Print the result
print(foldername)
My flow:

My flow failure:

Error massage:
Illegal characters in path.: Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Can't create folder 2023Jan
into C:\SFTPROOT\SDR_In\Archieved\. ---> System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.Flow.RPA.Desktop.Modules.Folder.Actions.FolderActions.CreateFolder(Variant newFolderPath, Variant newFolderName, Variant& newFolder)
--- End of inner exception stack trace ---
at Microsoft.Flow.RPA.Desktop.Modules.Folder.Actions.CreateFolder.Execute(ActionContext context)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)