Code of the Day: DOS Open an existing file or create it if it doesn’t exist


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /home/bateeqjg/public_html/news/wp-content/plugins/wp-syntax/wp-syntax.php on line 380
REM filename: openAndORCreateFileTXT.bat
rem\ >> file.txt && file.txt

The following will open a existing file named file.txt. However, it if doesn’t exist then it will create it for you then open it. This is very useful.

“rem\” Let’s you return a empty character.
“>> file.txt” appends the returned value on the left hand side, which in this case is nothing.
“&& file.txt” once the left hand operation is done, then open the file ( file.txt).

(Page view Count: 83)

Published by

Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.