用正斜杠代替反斜杠

时间:2019-12-02 11:18:38

标签: batch-file

任何人都可以帮助我了解以下代码的问题

SETLOCAL ENABLEDELAYEDEXPANSION
set currentDirectory = %CD%
set "currentDirectory = %currentDirectory:\=/%"

似乎没有用反斜杠代替正斜杠

1 个答案:

答案 0 :(得分:1)

set设置变量时,您需要知道变量在=之前和之后都包含空格。因此,您应该没有空格。下面的示例也较短,因为我们不必两次设置currentDirectory

@echo off
set "currentDirectory=%cd:\=/%"