- Batch Script Tutorial
- Batch Script - Home
- Batch Script - Overview
- Batch Script - Environment
- Batch Script - Commands
- Batch Script - Files
- Batch Script - Syntax
- Batch Script - Variables
- Batch Script - Comments
- Batch Script - Strings
- Batch Script - Arrays
- Batch Script - Decision Making
- Batch Script - Operators
- Batch Script - DATE & TIME
- Batch Script - Input / Output
- Batch Script - Return Code
- Batch Script - Functions
- Batch Script - Process
- Batch Script - Aliases
- Batch Script - Devices
- Batch Script - Registry
- Batch Script - Network
- Batch Script - Printing
- Batch Script - Debugging
- Batch Script - Logging
- Batch Script Resources
- Batch Script - Quick Guide
- Batch Script - Useful Resources
- Batch Script - Discussion
Batch Script - Writing to Files
Content writing to files is also done with the help of the redirection filter >. This filter can be used to redirect any output to a file. Following is a simple example of how to create a file using the redirection command to write data to files.
Example
@echo off dir C:\>C:\new.txt
The above code snippet first uses the DIR command to get the directory listing of the entire C:\ . It then takes that output and with the help of the redirection command sends it to the file new.txt.
Output
If you open up the file new.txt on your C drive, you will get the contents of your C drive in this file. Following is a sample output.
Volume in drive C is Windows8_OS Volume Serial Number is E41C-6F43 Directory of C:\ 12/22/2015 09:02 PM <DIR> 01 - Music 06/14/2015 10:31 AM <DIR> 02 - Videos 09/12/2015 06:23 AM <DIR> 03 - Pictures 12/17/2015 12:19 AM <DIR> 04 - Software 12/15/2015 11:06 PM <DIR> 05 - Studies 12/20/2014 09:09 AM <DIR> 06 - Future 12/20/2014 09:07 AM <DIR> 07 - Fitness 09/19/2015 09:56 AM <DIR> 08 - Tracking 10/19/2015 10:28 PM <DIR> 09 – Misc
batch_script_functions.htm
Advertisements