Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a txt file using batch file in a specific folder

I am trying to create a batch file which will create a text file in a specific folder. I am able to create a text file on my desktop, but I need to create a file in a specific file path.

For example in D:/Testing folder I wants to create a user defined text file.

@echo off  echo .>> dblank.txt 

I am using the above code to create a .txt file on my desktop.

I know this is a simple question but I searched google and have not found any good solution that could helpful to me.

like image 461
user1926138 Avatar asked Jan 27 '14 13:01

user1926138


People also ask

How do you create a TXT batch file?

To create a Windows batch file, follow these steps: Open a text file, such as a Notepad or WordPad document. Add your commands, starting with @echo [off], followed by, each in a new line, title [title of your batch script], echo [first line], and pause. Save your file with the file extension BAT, for example, test.

Can a batch file create files?

Introduction# One useful feature of batch files is being able to create files with them.

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


2 Answers

You have it almost done. Just explicitly say where to create the file

@echo off   echo.>"d:\testing\dblank.txt" 

This creates a file containing a blank line (CR + LF = 2 bytes).

If you want the file empty (0 bytes)

@echo off   break>"d:\testing\dblank.txt" 
like image 67
MC ND Avatar answered Sep 22 '22 13:09

MC ND


This code written above worked for me as well. Although, you can use the code I am writing here:

@echo off  @echo>"d:\testing\dblank.txt 

If you want to write some text to dblank.txt then add the following line in the end of your code

@echo Writing text to dblank.txt> dblank.txt 
like image 40
TRIDIB BOSE Avatar answered Sep 25 '22 13:09

TRIDIB BOSE