2

This is my script. I tried many ways, but can't escape % symbol.

@ECHO off
SETLOCAL DisableDELAYEDEXPANSION
CHCP 65001 >NUL

:start
set Input="C:\Transcode\ABC! code's 30% Special"
set Output="C:\Batch Script\DST&2"

REM set /p Input="Enter source folder link: "
REM set /p Output="Enter destination folder link: "  

set "SRC=%Input:"=%"
set "DST=%Output:"=%"

FOR /F "delims=" %%a IN ('DIR /b /s /a-d "%SRC%"') DO (
    call :mklink "%%a" "%%~na" "%%~xa" "%DST%"
)
Goto :EOF

   :mklink
    Set "FILENAME=%~2"
    Set "FILENAME=%FILENAME: =_%"
    Set "FILENAME=%FILENAME:-=_%"
    for %%b in ("%FILENAME:_=" "%") do (
        Echo %%b | FindStr /IRC:"wjpg" >Nul && (
            IF exist "%~4\ABC\%%~b%~3" del "%~4\ABC\%%~b%~3"
            ECHO mklink "%~4\ABC\%%~b%~3" "%~1" >> "%~4\log.txt" 2>&1
            mklink "%~4\ABC\%%~b%~3" "%~1"
        )
    )
    Goto :EOF

Attention: path can not change (don't add or remove character)

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Dang Long
  • 37
  • 1
  • 4
  • Didn't you try the answer I posted? What do you mean by "path"? Are you calling "Input" a "path"? The word "path" occurs nowhere in your script. You don't appear to be doing anything with the PATH system variable. This question needs more clarity. – lurker Dec 31 '19 at 13:26

1 Answers1

1

In a regular Windows batch file, you can escape a % in a string by using two of them:

set "Input=C:\Transcode\ABC! code's 30%% Special"

If you need double quotes as part of the string, then include them when referencing the variable: "%Input%".

aschipfl
  • 33,626
  • 12
  • 54
  • 99
lurker
  • 56,987
  • 9
  • 69
  • 103