删除最后一行开头echo 即可传送xcopy需要的变量
@echo off
for /f "tokens=1,2 delims==" %%i in (test.ini) do (
if "%%i"=="From_Dir" set Srcpath=%%j
if "%%i"=="To_Dir" set Dstpath=%%j
)
echo xcopy "%Srcpath%" "%Dstpath%"
@echo off
color 0a
title Unified Packing File 1.0
pushd "%~dp0"
SETLOCAL ENABLEDELAYEDEXPANSION
goto DEV_POINT
if "%~1" equ "" (
echo Please drag and drop a file or folder onto the batch program icon.
goto NORMAL_EXIT
)
:DEV_POINT
set APP_HOME=%~dp0
set CFG=config.ini
if not exist "%CFG%" (
echo %CFG% not found.
goto NORMAL_EXIT
)
for /f "usebackq eol=# tokens=1* delims==" %%i in ("%CFG%") do (
if "%%i" equ "__COMMENT_FILE" (
call :FN_TRIM "%%j"
set __COMMENT_FILE=!RTN_TRIM!
) else if "%%i" equ "__LOCK" (
call :FN_TRIM "%%j"
set __LOCK=!RTN_TRIM!
) else if "%%i" equ "__TEST" (
call :FN_TRIM "%%j"
set __TEST=!RTN_TRIM!
) else if "%%i" equ "__PASSWORD" (
set __PASSWORD=%%j
) else if "%%i" equ "__ENCRYPT_BOTH" (
call :FN_TRIM "%%j"
set __ENCRYPT_BOTH=!RTN_TRIM!
) else if "%%i" equ "__VOLUMES_SIZE" (
call :FN_TRIM "%%j"
set __VOLUMES_SIZE=!RTN_TRIM!
)
)
echo __COMMENT_FILE[%__COMMENT_FILE%]
echo __LOCK[%__LOCK%]
echo __TEST[%__TEST%]
echo __PASSWORD[%__PASSWORD%]
echo __ENCRYPT_BOTH[%__ENCRYPT_BOTH%]
echo __VOLUMES_SIZE[%__VOLUMES_SIZE%]
goto NORMAL_EXIT
:NORMAL_EXIT
popd
pause
exit
@rem ##############################FBP Begin
@title Function Batch Program 1.0
@color 0a
@echo Note: I can't run independently.
@ping /n 3 127.0.0.1 > nul
@exit
rem eg. call :FN_LENGTH " hey "
rem 参数必须使用双引号包裹,不允许包含特殊字符,如:'">&$*:^等等。
:FN_LENGTH
set /a RTN_LENGTH=0
set _LENGTH_ORI_STR=%*
set _LENGTH_ORI_STR=%_LENGTH_ORI_STR:~1,-1%
set _SURPLUS=%_LENGTH_ORI_STR%
:PROC_LENGTH_GAIN_CHAR
for /f "tokens=*" %%i in ("!_SURPLUS!") do (
set _SURPLUS=!_SURPLUS:~1!
call :PROC_LENGTH_GAIN_CHAR
set /a RTN_LENGTH+=1
)
goto :EOF
rem eg. call :FN_TRIM "%%j"
rem 参数必须使用双引号包裹,不允许包含特殊字符,如:'">&$*:^等等。
:FN_TRIM
set _TRIM_ORI_STR=%*
set _TRIM_ORI_STR=%_TRIM_ORI_STR:~1,-1%
call :FN_LENGTH "%_TRIM_ORI_STR%"
set /a _STR_LENGTH=%RTN_LENGTH%
set _FILTER=%_TRIM_ORI_STR: =%
if "%_FILTER%" equ "" (
set RTN_TRIM=
goto :EOF
)
set _FILTER=%_FILTER: =%
if "%_FILTER%" equ "" (
set RTN_TRIM=
goto :EOF
)
call :FN_LENGTH "%_FILTER%"
set /a _FILTER_LENGTH=%RTN_LENGTH%
if %_FILTER_LENGTH% equ 1 (
set RTN_TRIM=!_FILTER!
goto :EOF
)
if %_STR_LENGTH% equ 0 (
set RTN_TRIM=
goto :EOF
)
if %_STR_LENGTH% equ 1 (
set RTN_TRIM=!_TRIM_ORI_STR!
goto :EOF
)
set /a _LOOP_END=%_STR_LENGTH% - 1
set /a _STR_START=0
set /a _STR_END=0
for /l %%i in (0,1,%_LOOP_END%) do (
set _CHAR=!_TRIM_ORI_STR:~%%i,1!
if "!_CHAR!" equ " " (
echo NOP > nul
) else if "!_CHAR!" equ " " (
echo NOP > nul
) else (
set /a _STR_START=%%i
goto :PROC_TRIM_FIND_END
)
)
:PROC_TRIM_FIND_END
for /l %%i in (%_LOOP_END%,-1,0) do (
set _CHAR=!_TRIM_ORI_STR:~%%i,1!
if "!_CHAR!" equ " " (
echo NOP > nul
) else if "!_CHAR!" equ " " (
echo NOP > nul
) else (
set /a _STR_END=%%i
goto :PROC_TRIM_MERGE
)
)
:PROC_TRIM_MERGE
set /a _EXCEPT=-1 * (%_LOOP_END% - %_STR_END%)
if %_EXCEPT% equ 0 (
set RTN_TRIM=!_TRIM_ORI_STR:~%_STR_START%!
) else (
set RTN_TRIM=!_TRIM_ORI_STR:~%_STR_START%,%_EXCEPT%!
)
goto :EOF
rem eg. call :FN_SET_VAL GENDER " Male "
rem 估计不可行
:FN_SET_VAL
set %1=%2
goto :EOF
@rem ##############################FBP End