Reputation: 360
I'm trying to download a file from a webservice that either contains the string "empty" or something else. If "empty", I want to delete the file, else it should be moved and renamed.
To achieve this, I'm using wget.exe to download the file, this works perfectly.
This is what I have:
wget "myurl.com/webservice" -O output.txt
@echo off
set /p Build=<output.txt
if %Build% == "empty" (ECHO "EMPTY")
PAUSE
Test scenario: a file called output.txt with the String empty inside.
How can I modify and read the content? using set/p doesn't work.
Thank you in advance. Best
Upvotes: 0
Views: 335
Reputation: 24476
It appears that you're asking two different things. If all you want to do is move a file with a line reading empty
, you can use findstr
. On success, delete the file. On fail, move it.
wget "myurl.com/webservice" -O output.txt
@echo off
findstr /i "^empty$" output.txt >NUL && (
del output.txt
) || (
move output.txt "path\to\file.txt"
)
If you want to manipulate the contents of output.txt before moving it, we need more details about what you want to change. If you want to read the contents of output.txt line-by-line, Magoo's suggestion of a for /f
loop is the best way to do that.
Upvotes: 1
Reputation: 80113
@echo off
for /f "delims=" %%a in (output.txt) do echo("%%a"
should show you precisely what is contained in the file (assuming it is one line - this will show all non-empty lines if there's more than one...) but "contained in quotes"
.
This string must exactly match the string against which it is compared, thus
for /f "delims=" %%a in (output.txt) do if "%%a"=="empty" (echo EMPTY)
Note that stray spaces may appear, it's not clear whether the quotes are being used literally of to delimit the literal string that is contained in the file, and in there's a case-mismatch then if /i "%%a"=="empty"...
is required (/i is the "case-insensitive" switch)
Upvotes: 2