Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enableDelayedExpansion
- cls
- :: ------------------------------------------------------------------
- :: Sample Output
- :: ------------------------------------------------------------------
- :: [2013/10/22 23:07:26] "Finding item 1..."
- :: [2013/10/22 23:07:26] "Call -> :find ["("foo" "bar" "baz")" 1]"
- :: [2013/10/22 23:07:26] "The value is: "bar""
- :: ------------------------------------------------------------------
- :: ------------------------------------------------------------------
- :: Variable declarations
- :: ------------------------------------------------------------------
- set RETURN=-1
- set MY_LIST=("foo" "bar" "baz")
- set TARGET_INDEX=1
- :: -------------------------------------------------------------------
- :: Main procedure
- :: -------------------------------------------------------------------
- call :log "Finding item %TARGET_INDEX%..."
- call :find "%MY_LIST%" %TARGET_INDEX%
- call :log "The value is: %RETURN%"
- goto Exit
- :: -------------------------------------------------------------------
- :: Function declarations
- :: -------------------------------------------------------------------
- :find
- call :log "Call -> :find [%*]"
- set RETURN=-1
- set /a i=0
- for %%a in %~1 do (
- if !i! == %~2 (
- set RETURN=%%a
- )
- set /a i=!i!+1
- )
- goto:EOF
- :printDate
- for /f "tokens=2-4 delims=/ " %%a in ('echo %DATE%') do (
- set mydate=%%c/%%a/%%b)
- for /f "tokens=1-3 delims=/:./ " %%a in ('echo %TIME%') do (
- set mytime=%%a:%%b:%%c)
- echo|set /p="[%mydate% %mytime%] "
- goto:EOF
- :log
- call :printDate & echo %*
- goto:EOF
- :: -------------------------------------------------------------------
- :: End of script
- :: -------------------------------------------------------------------
- :Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement