You can avoid many of the problems that the changing $mircdir can cause, by referring to locations indirectly, instead of by the complete c:\path\filename.

Instead of using $mircdirSubFolder\filename.txt to refer to a filename, you can use instead SubFolder\filename.txt which works regardless what the $mircdir is. You can easily strip the mircdir out with $remove($mircdirSubFolder\filename.txt,$mircdir)