More Than Basicbatchfiles



Batch

Below is how to use the choice and set command in a batch file to give users a list of selectable options.

How to use set in a batch file

Amid the current public health and economic crises, when the world is shifting dramatically and we are all learning and adapting to changes in daily life, people need wikiHow more than ever. Your support helps wikiHow to create more in-depth illustrated articles and videos and to share our trusted brand of instructional content with millions of. Less than or equal to. Ask Question Asked 7 years, 4 months ago. Less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal That should explain what you want. The only other compare-op is which can be switched with the if not parameter. Other then that rely on these three letter ones.

Below is how you can use the set command to give batch file users the ability to press 1, 2, or 3 and perform the steps for the option pressed.

In the above batch file, the %choice% variable is assigned when the user enters data and presses enter with the set /p choice line. If 1, 2, or 3 is entered, goto goes to the corresponding label and performs the echo and goes to the end of the batch file.

  • See our set command page for further information and options.

How to use choice in a batch file

Below is how to use the choice command to give three options and perform a specific step.

In the above batch file, choice has the 1, 2, or 3 option. If any of these are pressed, it goes to the label with goto and echoes the number pressed.

  • See our choice command page for further information and options.

Additional information

  • See the choice our set page for further information about each of these commands.
-->

Copies one or more files from one location to another.

Note

You can also use the copy command, with different parameters, from the Recovery Console. For more information about the recovery console, see Windows Recovery Environment (Windows RE).

Syntax

Parameters

ParameterDescription
/dAllows the encrypted files being copied to be saved as decrypted files at the destination.
/vVerifies that new files are written correctly.
/nUses a short file name, if available, when copying a file with a name longer than eight characters, or with a file name extension longer than three characters.
/ySuppresses prompting to confirm that you want to overwrite an existing destination file.
/-yPrompts you to confirm that you want to overwrite an existing destination file.
/zCopies networked files in restartable mode.
/aIndicates an ASCII text file.
/bIndicates a binary file.
<source>Required. Specifies the location from which you want to copy a file or set of files. Source can consist of a drive letter and colon, a directory name, a file name, or a combination of these.
<destination>Required. Specifies the location to which you want to copy a file or set of files. Destination can consist of a drive letter and colon, a directory name, a file name, or a combination of these.
/?Displays help at the command prompt.

Remarks

  • You can copy an ASCII text file that uses an end-of-file character (CTRL+Z) to indicate the end of the file.

  • If /a precedes or follows a list of files on the command line, it applies to all files listed until copy encounters /b. In this case, /b applies to the file preceding /b.

    The effect of /a depends on its position in the command-line string:- If /a follows source, the copy command treats the file as an ASCII file and copies data that precedes the first end-of-file character (CTRL+Z).- If /a follows destination, the copy command adds an end-of-file character (CTRL+Z) as the last character of the file.

  • If /b directs the command interpreter to read the number of bytes specified by the file size in the directory. /b is the default value for copy, unless copy combines files.

  • If /b precedes or follows a list of files on the command line, it applies to all listed files until copy encounters /a. In this case, /a applies to the file preceding /a.

    The effect of /b depends on its position in the command–line string:- If /b follows source, the copy command copies the entire file, including any end-of-file character (CTRL+Z).- If /b follows destination, the copy command doesn't add an end-of-file character (CTRL+Z).

  • If a write operation cannot be verified, an error message appears. Although recording errors rarely occur with the copy command , you can use /v to verify that critical data has been correctly recorded. The /v command-line option also slows down the copy command, because each sector recorded on the disk must be checked.

  • If /y is preset in the COPYCMD environment variable, you can override this setting by using /-y at the command line. By default, you are prompted when you replace this setting, unless the copy command is executed in a batch script.

  • To append files, specify a single file for destination, but multiple files for source (use wildcard characters or file1+file2+file3 format).

  • If the connection is lost during the copy phase (for example, if the server going offline breaks the connection), you can use copy /z to resume after the connection is re-established. The /z option also displays the percentage of the copy operation that is completed for each file.

  • You can substitute a device name for one or more occurrences of source or destination.

  • If destination is a device (for example, Com1 or Lpt1), the /b option copies data to the device in binary mode. In binary mode, copy /b copies all characters (including special characters such as CTRL+C, CTRL+S, CTRL+Z, and ENTER) to the device, as data. However, if you omit /b, the data is copied to the device in ASCII mode. In ASCII mode, special characters might cause files to combine during the copying process.

  • If you don't specify a destination file, a copy is created with the same name, modified date, and modified time as the original file. The new copy is stored in the current directory on the current drive. If the source file is on the current drive and in the current directory and you do not specify a different drive or directory for the destination file, the copy command stops and displays the following error message:

  • If you specify more than one file in source, the copy command combines them all into a single file using the file name specified in destination. The copy command assumes the combined files are ASCII files unless you use the /b option.

  • To copy files that are 0 bytes long, or to copy all of a directory's files and subdirectories, use the xcopy command.

  • To assign the current time and date to a file without modifying the file, use the following syntax:

    Where the commas indicate that the destination parameter has been intentionally left out.

Batch Files Examples

Examples

To copy a file called memo.doc to letter.doc in the current drive and ensure that an end-of-file character (CTRL+Z) is at the end of the copied file, type:

To copy a file named robin.typ from the current drive and directory to an existing directory named Birds that is located on drive C, type:

Note

If the Birds directory doesn't exist, the file robin.typ is copied into a file named Birds that is located in the root directory on the disk in drive C.

To combine Mar89.rpt, Apr89.rpt, and May89.rpt, which are located in the current directory, and place them in a file named Report (also in the current directory), type:

Note

If you combine files, the copy command marks the destination file with the current date and time. If you omit destination, the files are combined and stored under the name of the first file in the list.

Create A Batch File

To combine all files in Report, when a file named Report already exists, type:

To combine all files in the current directory that have the .txt file name extension into a single file named Combined.doc, type:

To combine several binary files into one file by using wildcard characters, include /b. This prevents Windows from treating CTRL+Z as an end-of-file character. For example, type:

Caution

If you combine binary files, the resulting file might be unusable due to internal formatting.

How To Make Batch Files

  • Combining each file that has a .txt extension with its corresponding .ref file creates a file with the same file name, but with a .doc extension. The Copy command combines file1.txt with file1.ref to form file1.doc, and then the command combines file2.txt with file2.ref to form file2.doc, and so on. For example, type:

To combine all files with the .txt extension, and then to combine all files with the .ref extension into one file named Combined.doc, type:

Windows Batch File Basics

Additional References