Tutorial by Examples

There may be multiple reason why you want to create a text file in batch. But whatever the reason may be, this is how you do it. If you want to overwrite an existing text file use >. Example: @echo off echo info to save > text.txt But if you want to append text to an already existing t...
You may want to copy files from one place to another. In this example we'll teach you. You can use the command xcopy. The syntax is xcopy c:\From C:\To Example: @echo off xcopy C:\Folder\text.txt C:\User\Username\Desktop There are also switches you can use. If you want to view them open up co...
Using the move command, you can move files: @echo off cd C:\Foo\Bat\Baz move /Y Meow.bat "Meow Folder" >nul Meow.bat stands for which file to move. The "Meow Folder" moves Meow.bat to the Meow Folder. /Y says to not prompt for confirmation. Replacing that with /-Y makes ...
Using the DEL(alias for ERASE) command, one can remove files. @echo off del foo.ext This command will delete foo.ext from the current directory. One can also specify path and file, such as: del C:\Foo\Bar\Baz.ext But it is always ideal to put quotes (") around paths, see here for the r...
In this example, user BoeNoe showed how to use the command xcopy to copy files. There is also an extra command called copy. Here is a simple example: copy foo.ext bar.ext This copies foo.ext to bar.ext, and create bar.ext when it doesn't exist. We can also specify paths to the file, but it is a...
Batch file does not come with a built-in method for replacing nth line of a file except replace and append(> and >>). Using for loops, we can emulate this kind of function. @echo off set file=new2.txt call :replaceLine "%file%" 3 "stringResult" type "%file...

Page 1 of 1