Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Help Automatating CMD Commands


01 Dec 2012   #1

Windows 7 Ultimate x86
 
 
Help Automatating CMD Commands

I need help making a CMD script that will...

Open a certain directory
clear the screen
run a command

and then it must stay open


how would i do this?

My System SpecsSystem Spec
.

01 Dec 2012   #2
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

Hello Pedro,

You could use this in a .bat or .cmd file to do so. CLS will clear the screen in the command prompt. Pause will leave the command prompt open until you press a key to close it.

Code:
cd "full path of directory"
 
CLS
 
your command
 
pause
Hope this helps,
Shawn
My System SpecsSystem Spec
01 Dec 2012   #3

Windows 7 Ultimate x64
 
 

You can make a batch file

Cd (directory)
Start cmd.exe

This will open a new command prompt in the directory.
My System SpecsSystem Spec
.


01 Dec 2012   #4

Windows 7 Ultimate x86
 
 

i got it anyway after a bit of fiddeling.

Code:
echo off
cd C:\android-sdk-windows\platform-tools
cls
adb devices
echo off
ping 1.0.0.0 -n 1 -w 5000 >NUL
how would i make a batch file that detects a usb flash drive
prompts me to copy files
copies files
reports back
and then closes
My System SpecsSystem Spec
02 Dec 2012   #5

W7 Pro SP1 64bit
 
 

The adb app does not require the cd line and you might like pause better than ping... or not.

Code:
echo off
cls
C:\android-sdk-windows\platform-tools\adb.exe devices
pause

...detect a usb drive via batch file?

Are you wanting this batch file to run all of the time? ...always watching for a usb drive?
Will it always be the same usb drive that this batch file is looking for?
My System SpecsSystem Spec
02 Dec 2012   #6

Windows 7 Ultimate x86
 
 

Ok i got it. I made this yesterday and it is quite complicated...
I will post the batch later for viewing purposes.

How would i make a batch file to ask the user for his username,drive lettrs etc. Then it would make a backup of the above file.it would then modify certain lines in the above files and replace them with the inputed username etc
My System SpecsSystem Spec
02 Dec 2012   #7

W7 Pro SP1 64bit
 
 

Helping you might be simpler if you would detail what your plans are. I can only assume that you want to copy files from a usb stick to a user's "my doc..." area.

Quote   Quote: Originally Posted by pedroc1999 View Post
~~~
How would i make a batch file to ask the user for his username,drive letters etc....
Code:
echo off
set /p SomeName=
echo %SomeName%
pause
You could also just use the variable %username% which will return the name of the person currently logged on.
Code:
echo off
echo %username%
pause
Be aware that people can change their username.
I can be logged on as Fred and my files are under C:\Users\Bob\...
The variable %username% will return Fred...
...but you might want Bob for the path info.

You might find this code more useful:
Code:
echo off
echo %homepath%
pause
Also be aware that some usernames have spaces in them:
C:\Users\Tony the Tiger\...
Which means that you should put quotation marks around the path even if you don't need them for most users.


Quote   Quote: Originally Posted by pedroc1999 View Post
~~~
Then it would make a backup of the above file.it would then modify certain lines in the above files and replace them with the inputed username etc
Code:
echo %SomeName% > test.bat
echo SomeInfo >> test.bat
My System SpecsSystem Spec
02 Dec 2012   #8

Windows 7 Ultimate x86
 
 

ok so this is the long version

i am trying to make a batch file to backup all the files on my phone to my documents - i have finished this bit, tested and all is working

i want to publicate this batch so everyone can use it.That means making a 'setup.cmd' that will edit the actual backup batch to suit the users needs. the %username% command you suggested will be used to determin the actual username, but i need a way for the user to specify where his internal sdcard and external sdcard are and adjusting the file accordinly. i will upload the file so you can view it


Attached Files
File Type: bat Android File Backup.bat (2.6 KB, 8 views)
My System SpecsSystem Spec
02 Dec 2012   #9

Windows 7 Ultimate x86
 
 

Ok i done it now and will publish tomorow. I am on my phone so i havnt got the file here.this is my first batch i make and it turned out to be 3500+words so i started big.now my phone is safely backed up. I still need a way to access the system folder for complete backup
My System SpecsSystem Spec
02 Dec 2012   #10

W7 Pro SP1 64bit
 
 

'sleep' is not recognized as an internal or external command, operable program or batch file.

I would use %homepath% instead of %username%.

Using dates for the folders is good - but I would create a path more like:

...\year\month\day-time
or
...\year-month-day-time

Those folder structures will sort better.

I do not want to discourage you from learning/using command line batch files, but if you are going to be giving this to others, you might want to learn a scripting language like AutoHotKey or AutoIt.
My System SpecsSystem Spec
Reply

 Help Automatating CMD Commands




Thread Tools



Similar help and support threads for2: Help Automatating CMD Commands
Thread Forum
Solved Definitions of Commands General Discussion
Solved Bat commands.. General Discussion
.bat Help.. Is these commands safe? Themes and Styles
Solved Windows Run Commands General Discussion
Need help wih a .bat file commands Software
Run commands remembered ? General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:09 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33