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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
the_importer
Posts: 3
Joined: 18 Jun 2020 08:37

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

#1 Post by the_importer » 18 Jun 2020 09:15

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\

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

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

#2 Post by Aacini » 18 Jun 2020 11:31

Code: Select all

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

the_importer
Posts: 3
Joined: 18 Jun 2020 08:37

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

#3 Post by the_importer » 18 Jun 2020 12:52

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.

T3RRY
Posts: 250
Joined: 06 May 2020 10:14

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

#4 Post by T3RRY » 18 Jun 2020 13:17

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#!%

Post Reply