[solved] Merged input & output parameter in function ?
Posted: 08 Jun 2011 07:45
Hi
First post ... So big thanks to DosTips site for being there. Live saver when is comes to win/cmd/dos scripting.
Wondering about something. Is it possible to use a single var-name for both data-input and -output ?
I did see its possible when you use [set /A ..], but that's for numbers. But for string data all my attempts failed so far.
Looked closely at the general Functions help page at the DosTips website, but did not see anything in that direction either.
For example I have the following function.
Could this also be done with just one function parameter ?
First post ... So big thanks to DosTips site for being there. Live saver when is comes to win/cmd/dos scripting.
Wondering about something. Is it possible to use a single var-name for both data-input and -output ?
I did see its possible when you use [set /A ..], but that's for numbers. But for string data all my attempts failed so far.
Looked closely at the general Functions help page at the DosTips website, but did not see anything in that direction either.
For example I have the following function.
Code: Select all
:NormalizeFilespec - <var:Output> <"path":input> -- "normalize + strip posible trailing (path) backslash."
:: returns (additional) error(1) if filespec(file/path) is not existing.
IF "%~1" EQU "" ECHO Err(:NormalizeFilespec): missing first parameter.&EXIT 96001
IF "%~2" EQU "" ECHO Err(:NormalizeFilespec): missing second parameter.&EXIT 96002
SETLOCAL
set "path=%~f2"
if "%path:~-1%" equ "\" set "path=%path:~0,-1%"
if not exist "%path%" (set "err=123") else (set "err=0")
ENDLOCAL & set "%~1=%path%" & EXIT /b %err%
Could this also be done with just one function parameter ?
Code: Select all
:NormalizeFilespec - <var:Input/Output> -- "..."
:: how to get the data in variable X, which name is in $1 ?