Special Characters in paths

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Special Characters in paths

#1 Post by SIMMS7400 » 20 Jun 2017 01:35

HI Folks -

I have a few variables that have special characters in them. Is the only way around this to perform a replacement on each of the variables that use the path with special characters?

For instance: %HC_EXCEL_SPATH:^=%

Code: Select all

SET "HC_EXCEL_SPATH=C:\Finance ^& Accounting\FP^&A Files\R^&D Function ^& Site Support\Monthly Reporting\Models\Headcount\"
SET "HC_EXCEL_TPATH=C:\Finance ^& Accounting\FP^&A Files\R^&D Function ^& Site Support\Monthly Reporting\Models\Access\Headcount\"

>>%LOGFILE% (
ECHO.                                          
ECHO **********************************************************
ECHO Copy Headcount file^(s^) to Network Share Source Directory                          
ECHO **********************************************************
ECHO.                                          
)
::-- Headcount files copied to Headcount Process Source directory --::

>>%LOGFILE% (
ECHO Network Share Source Directory ^:
ECHO.
ECHO %HC_EXCEL_SPATH:^=%
ECHO.
)

SETLOCAL ENABLEDELAYEDEXPANSION

SET "A=0"
SET "B=0"
SET "NF2="
SET "NF3="

FOR %%H IN ( "%HC_CON%" "%HC_SEC%" "%HC_EMP%" ) DO (

   IF EXIST "%HC_PROCPATH%%%~H" (
      ECHO F | XCOPY /F /Y "%HC_PROCPATH%%%~H" "%HC_EXCEL_SPATH:^=%">nul

      IF %ERRORLEVEL%==0 (
         ECHO Copied ^: %%~H >>%LOGFILE%
      ) ELSE (
         ECHO Copy Failed ^: %%~H >>%LOGFILE%
         SET /A B+=1
         IF !B!==3 SET "NF3=T"& GOTO AbnormalExit
      )
   ) ELSE (
      SET /A A+=1
   )
IF !A!==3 SET "NF2=T"& GOTO AbnormalExit

)


Or am I setting this up incorrectly when needing to leverage those variables?

Post Reply