Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?

前端 未结 3 1366
情深已故
情深已故 2020-12-05 15:03

Just when I\'d thought I\'d seen it all with Windows path issues, I\'ve now encountered a case that only fails when \'/\' (forward-slash) is used as the path separator is us

3条回答
  •  天涯浪人
    2020-12-05 15:26

    I am not sure why the '/' is working in PS. Back to the history, DOS was based on UNIX and it is a small set of UNIX. In UNIX the path separator is '/', while in DOS it is '\'. I worked on some Windows and DOS apps before. In order to convert some UNIX pattern like commands or path and make sure they are valid DOS command or path, I wrote a small converter to transform '/' to '\' like this:

    string fileNameFromWeb;
    ...
    string windowsFile = fileNameFromWeb.repleace("/", @"\");
    

    You may add this feature to tolerant '/' in your app in case of accessing to files in Windows. I guess PS may have this type converter to allow command or path using '/' or '\', or Windows will take '/' in file name.

提交回复
热议问题