Help Automatating CMD Commands

Page 1 of 3 123 LastLast

  1. Posts : 1,326
    Windows 7 Ultimate x86
       #1

    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 Computer


  2. Posts : 72,045
    64-bit Windows 11 Pro for Workstations
       #2

    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 Computer


  3. Posts : 881
    Windows 7 Ultimate x64
       #3

    You can make a batch file

    Cd (directory)
    Start cmd.exe

    This will open a new command prompt in the directory.
      My Computer


  4. Posts : 1,326
    Windows 7 Ultimate x86
    Thread Starter
       #4

    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 Computer


  5. Posts : 10,485
    W7 Pro SP1 64bit
       #5

    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 Computer


  6. Posts : 1,326
    Windows 7 Ultimate x86
    Thread Starter
       #6

    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 Computer


  7. Posts : 10,485
    W7 Pro SP1 64bit
       #7

    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.

    pedroc1999 said:
    ~~~
    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.


    pedroc1999 said:
    ~~~
    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 Computer


  8. Posts : 1,326
    Windows 7 Ultimate x86
    Thread Starter
       #8

    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
    Help Automatating CMD Commands Attached Files
      My Computer


  9. Posts : 1,326
    Windows 7 Ultimate x86
    Thread Starter
       #9

    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 Computer


  10. Posts : 10,485
    W7 Pro SP1 64bit
       #10

    '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 Computer


 
Page 1 of 3 123 LastLast

  Related Discussions
Our Sites
Site Links
About 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 08:56.
Find Us