Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Scripting (https://www.askmehelpdesk.com/forumdisplay.php?f=455)
-   -   Does anyone know anything about batch scripting? (https://www.askmehelpdesk.com/showthread.php?t=785110)

  • Feb 21, 2014, 06:21 PM
    InfoJunkie4Life
    Does anyone know anything about batch scripting?
    I'm working on a complex script; it employs nothing more than native commands for NT 5.2 and newer for compatibility purposes. I have a function within it that seems to be misbehaving and freezing up. Ideally it would be called "call :csvEdit "query:searchString" | "append:appendString"

    The append section functions perfectly.

    The query Does not. It is supposed to search each line of the file and list any line with a number to choose one that matches the query. The search string would then be parsed by a different function within the script to load the information into environmental variables. The output is environmental %csvOut%.

    Code:

    :csvDB :: "query:searchString" OR "append:appendString" (query will return the whole line or 0 for no match | appendstring will return 1/0 success/fail)
    setlocal enabledelayedexpansion enableextensions
    set netRoot=c:\users\Timothy\Desktop
    set "str2=%1"
        if not x%str2:query=% == x%str2% goto :query
        if not x%str2:append=% == x%str2% goto :append
        if 1 == 1 (
            set output=error
            goto :333
            )
        :append
            for /f "usebackq tokens=2 delims=:" %%a in ('%str2%') do (
                echo %%a >> %netRoot%\customers.csv
                if %errorlevel% == 0 set output=1
                if %errorlevel% NEQ 0 set output=0
                )
        goto :333
        :query
            set /a "n=0"
            for /f "usebackq tokens=2 delims=:" %%A in ('%str2%') do (
                for /f "usebackq tokens=* delims=," %%a in (`findstr /I /C:%%A %netRoot%\customers.csv`) do (
                    set /a "n+=1"
                    echo !n! %%a %%b %%c %%d %%e %%f %%g %%h %%i
                    set "arr[!n!]=%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i"
                    )
                if !n! == 0 set "output=0" & goto :333 & echo Not Found
                echo Choose the correct database entry
                set /p choice=Enter 0 for Not Present
                if !choice! == 0 set output=0 & goto :333
                )
            set output="%arr[!choice!]%"
            goto :333
    :333
    (endlocal
        set "csvOut=%output%"
    )
    goto eof


  • All times are GMT -7. The time now is 05:31 PM.