Change backslash to forward slash in windows batch file

后端 未结 5 2177
醉话见心
醉话见心 2020-12-24 06:26

I\'m trying to convert all backslashes () to forward slashes (/) in a variable which contains a file name and location. I\'ve read about this and seen:

%vari         


        
5条回答
  •  清歌不尽
    2020-12-24 06:30

    This seems to work for me:

    echo off
    
    setlocal enabledelayedexpansion
    
    FOR %%f IN ("C:\tools\workspace\*") DO (
      set old=%%f
      echo !old!
      set new=!old:\=/!
      echo !new!  
      echo.                 
    )
    

    Using a seperate variable rather than the loop variable makes the difference, along with enabling delayed expansion as the variable substittion syntex using the loop variable %%f dosn't seem to work.

提交回复
热议问题