最近在node中傳入路徑(eg: c:\usr\file)調用python,但python不識別反斜槓(\),因爲會當作轉義進行處理,而node中在window下識別(\),並且_dirname中也是(\),爲了讓python運行,所以進行替換。
let input="c:\user\myfile\file"
let forward=input.replace(/\\/g,'%5C')//"c:%5Cuser%5Cmyfile%5Cfile"
input=forward.replace(/%5C/g,'/')//"c:/user/myfile/file"