Jump to content

Windows Batch Scripting/File Commands

From Wikibooks, open books for an open world

3. File Commands

[edit | edit source]

This chapter covers the following commands:

  • COMP - Compares the contents of two files or sets of files.
  • FC - Compares two files or sets of files, and displays the differences between them.
  • FIND - Searches for a text string in a file or files.
  • FINDSTR - Searches for strings in files.
  • MORE - Displays output one screen at a time.
  • PRINT - Prints a text file.
  • SORT - Sorts input.
  • TYPE - Displays the contents of a text file.

The TYPE Command

[edit | edit source]

The TYPE command display the contents of a file. There are no options for the TYPE command.

C:\>TYPE README.TXT
This is a table of contents for "Editing Guide to Windows Commands"

  File and Directory Management
  File Commands
C:\>

The SORT Command

[edit | edit source]

The SORT command will sort lines of text from a file.

Orange
Banana
Apple
Pear
Strawberry
Bluberry
Blackberry

--------
File: fruits.txt
C:\>sort fruits.txt
Apple
Banana
Blackberry
Bluberry
Orange
Pear
Strawberry

C:\>

The /R option will sort in reverse order.

C:\>sort /R fruits.txt
Strawberry
Pear
Orange
Bluberry
Blackberry
Banana
Apple

C:\>

The MORE Command

[edit | edit source]

The MORE command will display output or contents of file a screenful at a time. It is especially useful when piping it with certain commands (such as DIR or TASKLIST) that produce very long output.

For example:

C:\>tasklist | more