Page 1 of 1

Is it possible to create a variable that will change a data path in a command?

Posted: 18 Jun 2020 09:15
by the_importer
Hi there,

I'm trying to make a batch file that will run a program which needs to be applied to different paths everytime. Now besides manually changing the path everything which is literally 6 numbers to edit, I was wondering if it would be possible to simply have a the command ask me that 6 digit number and apply it to me in the command line. Example:

Instead of setting the number myself
C:\Data\Hosted\Company000000\Profiles\

I would like something like this:

Enter Client Number:
C:\Data\Hosted\Company%ClientNo%\Profiles\

Re: Is it possible to create a variable that will change a data path in a command?

Posted: 18 Jun 2020 11:31
by Aacini

Code: Select all

set /P "ClientNo=Enter Client Number: "
echo C:\Data\Hosted\Company%ClientNo%\Profiles\
Antonio

Re: Is it possible to create a variable that will change a data path in a command?

Posted: 18 Jun 2020 12:52
by the_importer
Aacini wrote:
18 Jun 2020 11:31

Code: Select all

set /P "ClientNo=Enter Client Number: "
echo C:\Data\Hosted\Company%ClientNo%\Profiles\
Antonio
Works perfectly, thanks mate.

Re: Is it possible to create a variable that will change a data path in a command?

Posted: 18 Jun 2020 13:17
by T3RRY
A slightly over the top means that ensures the input is numerical and of the desired length.

Code: Select all

@Echo off
    (Set \n=^^^
%= Newline Var - Do not modify =%
)
Set "Profile=C:\Data\Hosted\Company------\Profiles\"

::: [Fixed Length Input Macro]
::: Usage: %DATAENTRY% [Var Name] [Choice character options] [Input Length] [Optional: M - mask input]
Set DATAENTRY=For %%n in (1 2) Do If %%n==2 (%\n%
    For /F "Tokens=1,2,3,4 Delims= " %%G in ("!INPUT!") Do (%\n%
	^<Nul Set /P "=%%G: "%\n%
        Set "%%G="%\n%
        For /L %%# in (1 1 %%I) Do (%\n%
            For /F "Delims=" %%C In ('Choice /N /C:%%H') Do (%\n%
                If /I "%%J" == "M" (^<Nul Set /P "=*") Else ^<Nul Set /P "=%%C"%\n%
                Set "%%G=!%%G!%%C"%\n%
            )%\n%
        )%\n%
    )%\n%
    Echo/%\n%
) Else Set INPUT=
::: [End Macro Definition]

Setlocal EnableDelayedExpansion
%DATAENTRY% ACC# 0123456789 6
Echo/%Profile:------=!ACC#!%