Copy File: Illegal characters in path. Trying to use the copy file function

Not sure why I keep getting this I pull the doctors name out using Regex, as a variable of DoctorName is IEnumerable this is what I have

in the for each file in Directory.GetFiles(“files\Output”,“*.pdf”)

to: “files\Output" + DoctorName.ToString.Replace(”",“\”) + “.pdf”


What I am doing is rewriting the PDF with the DoctorName variable

Kindly note: the part with the root Directory (e.g c:) and maybe some sub folders is missing

Hello @jeff.shubzda

Use the below expression in To field and try :

Environment.CurrentDirectory+“\files\Output" + DoctorName.ToString.Replace(”_”,“”) + “.pdf”

Make sure u have the right value in DoctorName variable.


When I use the write line I get this in the output
“This is the doctors name” + DoctorName(0).Value
It seems to get the right file to overwrite
what file is this - files\Output\Patient Satisfaction Quarterly Provider 2022_1.pdf

This is what I have in the To: “files\Output" + DoctorName(0).ToString.Replace(”_“,”") + “.pdf”

In your write line you are getting Dr.Smith but in the above expression you are replacing “-”, what is the reason behind this operation? Probably you have to replace"." here

Hey @jeff.shubzda Please give the complete root path in the To property.
Thanks and Regards.

I think the illegal character is this in the string coming out DoctorName = Abichi, Ajay MD

is the comma the issue?
the To: “files\Output" + DoctorName(1).ToString.Replace(”,“,”") + “.pdf”

@jeff.shubzda ,

Put these expressions in write line and share us the output screenshot
Write line 1 : “files\Output" + DoctorName(0).ToString.Replace(“.”,”“) + “.pdf”
Write line 2 : “files\Output” + DoctorName(0).ToString.Replace(”_“,”") + “.pdf”

Thanks for the help the comma was giving me the issues so I cleaned up the data using an assign and used the clean data string to rename the PDF files. "files\Output" + strCleanPath + “.pdf”

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.