I am problem splinting the string in a loop. I have a subroutine (:STRING_SPLIT ) that splits the string by delimiter and return the split value. But the returned value is empty.
So for the debug purpose I called ":STRING_SPLIT" in another wrapper subroutine ":SPLIT_WRAP" to check if the string split value is retuned and yes I am getting the value I want.
But I am not getting this string split value in the main.
My Requirement:-
-----------------------
I have a folder structure like
+PHASE1 ( Directory)
++PREFERENCES ( Sub - Directory)
+++SITE ( Sub Sub - Directory)
+++GROUP ( Sub Sub - Directory)
++++FIlE1.xml
++++FIlE2.xml
++++RUN.bat
Code:-
-----------------
Code: Select all
:: Set TITLE name...
SET JOB_TITLE=Executing:{ %ROOT_FOLDER% }
TITLE %JOB_TITLE%
ECHO #=================== START:: %ROOT_FOLDER% ========================#
FOR /f "tokens=*" %%D IN ('DIR /B /AD /ON') DO (
ECHO #---"%%D"---#
CD "%%D"
FOR /f "tokens=*" %%F IN ('DIR /B *') DO (
IF /I "%%D"=="Preferences" (
REM ECHO Importing file "%%F"...
IF /I "%%F"=="group" (
REM ECHO DO NOTHING..
CALL :LOAD_SUB "group" %%D
) ELSE IF /I "%%F"=="role" (
REM ECHO DO NOTHING..
CALL :LOAD_SUB "role" %%D
ECHO.
) ELSE (
ECHO Importing file "%%F"...
)
)
)
CD ..
)
ECHO #=================== END:: %ROOT_FOLDER% ==========================#
cmd
:endext
endlocal
set EXITVALUE=%ERRORLEVEL%
:LOAD_SUB
::SETLOCAL
ECHO.
::SET CURRENT_DIR=%~1
REM ECHO I am processing %~1 preferences.
ECHO #---"%~2":"%~1"---#
CD "%~1"
FOR /f "tokens=*" %%P IN ('DIR /B *') DO (
:: IF EXIST *.xml( ECHO Importing file "%%P"... )
ECHO Processing file/directory "%%P"...
:: ECHO.CURRENT_DIR : %CURRENT_DIR%
IF /I "%~2"=="Preferences" (
IF /I "%~1"=="role" (
CALL:STRING_SPLIT "%%P" "." "FileName" "FileExtn"
ECHO.FileName : %FileName% REM $$$ ERROR : EMPTY VALUE
ECHO.FileExtn : %FileExtn% REM $$$ ERROR : EMPTY VALUE
IF /I "%FileExtn%"=="XML" (
:: CALL IMPORT COMMAND
:: CALL :IMPORT_PREFERENCES "%%P"
)
)
)
)
CD..
::ENDLOCAL
GOTO:EOF
:STRING_SPLIT
:: CALL:STRING_SPLIT %data% "." "FileName" "FileExtn"
SETLOCAL ENABLEDELAYEDEXPANSION
SET MY_STRING=%~1
SET DELIMITER_CHAR=%~2
::ECHO.MY_STRING : %MY_STRING%
::ECHO.DELIMITER_CHAR : %DELIMITER_CHAR%
FOR /f "tokens=1* delims=%DELIMITER_CHAR%" %%x IN ("%MY_STRING%") DO SET FileName=%%x&SET FileExtn=%%y
::ECHO.FileName : %FileName%
::ECHO.FileExtn : %FileExtn%
ENDLOCAL & SET %~3=%FileName% & SET %~4=%FileExtn%
::exit /b
GOTO:EOF
:SPLIT_WRAP
SETLOCAL
SET tSTRING=%~1
SET DEL_CHAR=%~2
ECHO.tSTRING : %tSTRING%
ECHO.DEL_CHAR : %DEL_CHAR%
CALL :STRING_SPLIT %tSTRING% %DEL_CHAR% "FileName" "FileExtn"
ECHO.FileName : %FileName%
ECHO.FileExtn : %FileExtn%
ENDLOCAL & (SET %~3=%FileName%) & ( SET %~4=%FileExtn% )
GOTO:EOF