Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch User input

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
I would like to know how to take an user input using a MS Dos batch file.
I would like to run a bat script and allow the users to select the environment they would like to enter.
Say if the user enters Test1 or Test2
then I would need to go to Test1 or Test2 folder and then copy all the files for Test2 to their local folder Just the ones that have changed.

Could anyone please let me know how I can use the user input to start with.

Many thanks
 
Code:
SET /P RESULT=[Choose environment (1/2)]
ECHO You entered %RESULT%
SET RESULT=

You will of course need to check that what they have entered is a valid option prior to the copy.

John
 
Thanks for the link John. It looks like a good product but the problem would be that I am looking at shipping this .bat file to the users.

They have their drive say G:\Drive mapped to the Share where I will release all the files for their test environment. All the users need to do is double click on this .bat file and it would copy the files to their local C:\Programs\ folder recursively.

Would this mean that the syncToy will need to be installed on others PC as well in order for this to work.

Otherwise does xcopy allow us to use recursive copy of the folder from a mapped network drive to the local drive for just those files that have changed. Is this possible ?

Many Thanks
 
Is there a command line for us to use SyncTool.
This would be great.
 
Milleniumlegend:

/A Copies only files with the archive attribute set, doesn't change the attribute.
/M Copies only files with the archive attribute set, turns off the archive attribute.
 
Synctoy is GUI-based and would need local installs for all users.

For XCOPY:

XCOPY source destination /y /d /e /c /i /f /h /k /o /v

/y allows the command to overwrite existing files without input from the user. The /Y switch helps in an automation process.

/d:m-d-y copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.


/e copies directories and subdirectories, including empty ones.

/c continues copying even if errors occur.

/i if destination does not exist and copying more than one file, assumes that destination must be a directory.

/f displays full source and destination file names while copying.

/h copies hidden and system files also.

/k copies attributes. Normal XCOPY will reset read-only attributes.

/o copies file ownership and ACL information. This will not work correctly under Windows 95/98/ME

/v verifies each new file. The /V is a good choice.
 
Thanks for the information on the xcopy. This is a great help.

Aron.
 
I need one more clarification. I am entering the following.
Code:
IF %RESULT% == 1 goto TEST%RESULT%
IF %RESULT% == 2 goto TEST%RESULT%
IF %RESULT% == 3 goto TEST%RESULT%
IF %RESULT% == 4 goto TEST%RESULT%
IF %RESULT% >= 5 goto LAST

IF the result is anything more than 4 then it needs to go to LAST which basically is End of Script. How can I do that?

Also, with XCOPY.

If the Source folder has couple of directories and the destination does not will this copy the files missing on the destination folder with this command

Code:
SET SOURCE="F:\BATCH\Velocity\upload\Client 5.2.7"
SET DEST="F:\Temp\pf\Velocity"
XCOPY %source% %destination% /y /d /e /c /i /f /h /k /o /v

 
Q: "IF the result is anything more than 4 then it needs to go to LAST which basically is End of Script. How can I do that?"

A: Rewrite as:

IF %RESULT% == 1 goto TEST%RESULT%
IF %RESULT% == 2 goto TEST%RESULT%
IF %RESULT% == 3 goto TEST%RESULT%
IF %RESULT% == 4 goto TEST%RESULT%
goto LAST

This will handle any response other than 1,2,3,or 4 as a branch to LAST, including a NULL reponse.

Q: "If the Source folder has couple of directories and the destination does not will this copy the files missing on the destination folder with this command..."

A: Yes, /e copies directories and subdirectories, including empty ones.

 
I have one more question on this one.

Code:
SET SRCSHORTCUTS="F:\BATCH\\shortcuts\"
SET DESTSHORTCUTS="F:\Temp\shortcuts"

IF %RESULT% == 1 goto TEST%RESULT%
IF %RESULT% == 2 goto TEST%RESULT%
IF %RESULT% == 3 goto TEST%RESULT%
IF %RESULT% == 4 goto TEST%RESULT%
IF /i %RESULT% == P goto TEST%RESULT%
IF /i %RESULT% == U goto TEST%RESULT%

:TEST1
echo "Entered Test1"
XCOPY %SOURCE% %DEST% /y /d /e /c /i /f /h /k /o /v
XCOPY %SRCSHORTCUTS%\t%RESULT%DESTSHORTCUTS% /y /d /e /c goto LAST

I am trying to copy from the folder under F:\BATCH\\shortcuts\t1 etc for each environment.
 
SET SRCSHORTCUTS="F:\BATCH\shortcuts"
SET DESTSHORTCUTS="F:\Temp\shortcuts"

IF %RESULT% == 1 goto TEST%RESULT%
IF %RESULT% == 2 goto TEST%RESULT%
IF %RESULT% == 3 goto TEST%RESULT%
IF %RESULT% == 4 goto TEST%RESULT%
IF /i %RESULT% == P goto TEST%RESULT%
IF /i %RESULT% == U goto TEST%RESULT%

:TEST1
echo "Entered Test1"
XCOPY %SOURCE% %DEST% /y /d /e /c /i /f /h /k /o /v
XCOPY %SRCSHORTCUTS%\t%RESULT% %DESTSHORTCUTS% /y /d /e /c goto LAST
 
Code:
[Choose test environment (1/2/3/4/5/P(PNL)/U(UAT))]1
You entered 1
"Entered Test1"
Invalid path
0 File(s) copied
[B]Invalid number of parameters[/B]
0 File(s) copied
"Finished Syncing"

the folder structure exists for SRCSHORTCUTS and they have files underneath. But I guess this expression
%SRCSHORTCUTS%\t%RESULT% gives me an error.
 
Another thing that I noticed was If I use the following command it works fine. I get Invalid path if I run the same command again.

XCOPY %SRCSHORTCUTS%\t1 %DESTSHORTCUTS% /y /d /e /c /i /f /h /k /o /v


 
SET SRCSHORTCUTS="F:\BATCH\\shortcuts\"
SET DESTSHORTCUTS="F:\Temp\shortcuts"

IF %RESULT% == 1 goto TEST%RESULT%
IF %RESULT% == 2 goto TEST%RESULT%
IF %RESULT% == 3 goto TEST%RESULT%
IF %RESULT% == 4 goto TEST%RESULT%
IF /i %RESULT% == P goto TEST%RESULT%
IF /i %RESULT% == U goto TEST%RESULT%

:TEST1
echo "Entered Test1"
XCOPY %SOURCE% %DEST% /y /d /e /c /i /f /h /k /o /v
XCOPY %SRCSHORTCUTS%\t%RESULT%DESTSHORTCUTS% /y /d /e /c
goto LAST

 
Code:
:TEST1
echo "Entered Test1"
SET SRCSHORTCUTS=%SRCSHORTCUTS%t%RESULT%\
echo %SRCSHORTCUTS%
XCOPY %SOURCE% %DEST% /y /d /e /c /i /f /h /k /o /v
XCOPY %SRCSHORTCUTS% %DESTSHORTCUTS% /y /d /e /c /i /f /h /k /o /v
goto LAST

The output looks something like this.
Code:
[Choose test environment (1/2/3/4/5/P(PNL)/U(UAT))]: 1
You entered 1
"Entered Test1"
F:\BATCH\shortcuts\t1\
Invalid path
0 File(s) copied
Invalid number of parameters
0 File(s) copied
"Finished Syncing"

The issue here is if I run the same thing with hardcoded path it seems to work not for this one though.the following works

SET SRCSHORTCUTS="F:\BATCH\shortcuts\"
SET DESTSHORTCUTS="F:\Temp\shortcuts"

XCOPY %SRCSHORTCUTS\t1% %DESTSHORTCUTS% /y /d /e /c /i /f /h /k /o /v


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top