Notifications
Clear all

[Closed] dotnet Path issues: Illegal characters in path

Hi all

I have another strange issue hapening here.

A path could be:
c: emp
or
c:\mystuff emppath\more stuff in here\and more here\finalpath
or any other path

…and I read that into a variable “myPathTemp” and add stuff to it and it works perfectly fine like so:

DosCommand ("\"" + myPathTemp + @"	emp path\myBatfile.bat" + "\"")

But, if I have a function using dotnet to replace text in the bat file like so:

 fn replaceTxtInFile fileName oldTxt newTxt =
 (
 	local s = dotnetClass "System.IO.File"
 	s.WriteAllText fileName ((s.ReadAllText fileName asdotnetobject:on).Replace oldTxt newTxt)
 )

And then use the command:

replaceTxtInFile ("\"" + myPathTemp + @"	emp path\myBatfile.bat" + "\"") "hello" "bye"

Then I get an ERROR:
– Runtime error: dotNet runtime exception: Illegal characters in path. (Even though its the EXACT PATH as before)

Whats up with that? How can i make it work with dotnet?

3 Replies

You could use the pathConfig.appendPath to properly create the paths, instead of using +. You can also use C# System.IO.Path.Combine() for the same effect.

Cheers,

1 Reply
(@morne)
Joined: 10 months ago

Posts: 0

Thanks that works perfectly!

 lo1

Place the entire path into a variable and print it before calling the method. That will show you what’s wrong with it.