Tahir Soomro
Tahir Soomro

Reputation: 21

Replacement of backslash with forward slash

Can anyone help me understand what is wrong with following code

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

It doesn't seem to be replacing the forward slash with backward slash

Upvotes: 1

Views: 97

Answers (1)

user7818749
user7818749

Reputation:

When setting variables, you need to know that variables include the whitespace before and after the = You should therefore have no spaces. The below example is also shorter as we do not have to set currentDirectory twice:

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

Upvotes: 1

Related Questions