Solved How do I create a new file after validating given string

March 29, 2017 at 17:54:41
Specs: Windows 10
How do I create a new file after validating given string in a file. If not found it has to create empty file.

See More: How do I create a new file after validating given string

Report •

#1
March 30, 2017 at 00:42:11
✔ Best Answer
test.bat
----------------------------
@echo off
for /f "tokens=*" %%a in (file.txt) do set "variable=%%a"&goto next
:next
if not "%variable%"=="string" (echo off>emptyfile.txt) else (echo string was found!&pause>nul)
exit /b
----------------------------
::echo. for a 2 byte file with an extra blank line
::echo off for a 0 byte file

file.txt
----------------------------
string

----------------------------

if you change it to tring it will make an empty file called emptyfile.txt

Please show some example before and after, since i think im missing the point >.<

Simple solutions are often the best

message edited by hidde663


Report •
Related Solutions


Ask Question