nodejs調用python單反斜槓“\”轉正斜槓“/“

最近在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"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章