Problem solve Get help with specific problems with your technologies, process and projects.

Creating batch files using the DOS 'Copy Con' command

Microsoft Windows users may find it convenient to create a batch file on-the fly, without having to open up an ASCII text editor. Here's how.

Please let us know how useful you find this tip by rating it below! If you have a useful Windows tip, timesaver...

or workaround to share, submit it to our tip contest and you could win a prize!

Microsoft Windows users may sometimes find it convenient to create a batch file on-the fly -- without having to open up an ASCII text editor or creating an ASCII text files using their resident word processor.

A very simple and effective DOS command (perhaps forgotten or unknown to most users) is the "COPY CON" command.

To create the following sample ASCII batch file in the user's root directory (which when executed will display the contents of the user's root directory on the bootable partition of the user's hard drive) do the following:


  2. Exit Windows by selecting the DOS or command prompt from its menu selection area. Note that when exiting from Windows (all versions), the user will be placed at the C: Windows directory by default.


  3. To go to the root directory and create the sample ASCII batch file, type the following (without quote marks):
    "CD" and press the <ENTER> key.
    (The DOS command prompt C:> will appear).


  4. Next, type "COPY CON LOOK.BAT" and press the <ENTER> key. (LOOK.BAT will be the name of the sample ASCII batch file and to execute this file after it has been created, the user need only type "LOOK" and press the <ENTER> key at the DOS command prompt C: >).


  5. Next, type "CLS" and press the <ENTER> key.
    (This command will clear the monitor screen prior to executing the remainder of the batch file's commands).


  6. Next, type "ECHO OFF" and press the <ENTER> key.
    (This command will prevent the sample batch commands from appearing on the monitor screen as they are executed).


  7. Next, type "DIR/P" and press the <ENTER> key.
    (The "DIR" command displays all of the directories and files contained in the user's root directory C: >).

    The "/P" switch limits the display of the root directory's contents to one full screen of data at a time and places the command prompt "Press Any Key To Continue" at the bottom of each single page display.

    If the root directory contains a large number of directories and files, the user will be presented with numerous screens of data and can then view each one separately. Then continue on by pressing any key to continue, until all data content has been displayed.


  8. Lastly, press the "<CTRL> + Z" keys simultaneously.
    (This will end creation of the sample ASCII batch file "LOOK.BAT.")

To execute this batch file, the user need only type "LOOK" while at the DOS command prompt C: >. The user will then see all of the directories and files located in the root directory C: of the user's hard drive.

If the user wishes to edit the sample batch file "LOOK.BAT" just created, the user may utilize the DOS "EDIT.COM" program (in all Windows versions) by typing "EDIT LOOK.BAT" and pressing the <ENTER> key. The three command lines, "CLS, ECHO OFF, and DIR/P" will be presented on screen.

Clicking the left mouse button on the FILE portion of the uppermost menu will allow the user to select "EXIT" from the pull-down menu, thus returning the user to the DOS command prompt C: >.

NOTE: Users are advised not to use conventional word processors (without ASCII file creation/editing features) because "high order ASCII characters or machine language" inserted by such word processors in a batch file will render it inoperative.

This was last published in November 2005

Dig Deeper on Windows Server and Network Security

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

Window Server 2012 not work a command copy con