Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get two or more commands together into a batch file

I want to enter a command in command prompt after reaching a specific location. How can I achieve this?

e.g.,

set PathName="X:\Web Content Mgmt\Completed Filtering\2013_Folder"
set comd="dir /b /s *.zip"
start "cmd" cd /d %PathName%

I am opening the command prompt and giving it a path using PathName. Now after reaching that specific path I want to insert the comd variable into the command prompt to get the desired result.

These are the specific commands I am trying to execute in the batch file:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\anoopn>x:
X:\>cd
X:\Web Content Mgmt\Completed Filtering\2013_Folder
X:\Web Content Mgmt\Completed Filtering\2013_Folder> dir /b /s *.zip > C:\Users\anoopn\Desktop\abc.csv
like image 957
Anoop Avatar asked Jul 08 '13 10:07

Anoop


4 Answers

To get a user Input :

set /p pathName=Enter The Value:%=%
@echo %pathName%

enter image description here

p.s. this is also valid :

set /p pathName=Enter The Value:

like image 173
Royi Namir Avatar answered Oct 22 '22 11:10

Royi Namir


You can use the following command. The SET will set the input from the user console to the variable comment and then you can use that variable using %comment%

SET /P comment=Comment: 
echo %comment%
pause
like image 41
Sunil Garg Avatar answered Oct 22 '22 12:10

Sunil Garg


Try this: edited

@echo off
set "comd=dir /b /s *.zip"
set "pathName="
set /p "pathName=Enter The Value: "
cd /d "%pathName%"
%comd%
pause
like image 2
foxidrive Avatar answered Oct 22 '22 13:10

foxidrive


set "PathName=X:\Web Content Mgmt\Completed Filtering\2013_Folder"
set "comd=dir /b /s *.zip"
cd /d "%PathName%"
%comd%
like image 2
Endoro Avatar answered Oct 22 '22 12:10

Endoro