grgoelyk
grgoelyk

Reputation: 437

Delete wget download if incomplete in Windows batch

When I download jpegs from an unreliable website, the downloads are often incomplete. Is there a wget option to delete incomplete downloads?

Upvotes: 0

Views: 408

Answers (1)

MC ND
MC ND

Reputation: 70933

You can check the exit status of wget

set "output=x:\somewhere\myFile.dat"
wget -O "%output%" "http://somewhere.com/this"
if errorlevel 1 del "%output%" 2>nul 

Or using conditional execution operator || (execute next command if the previous fails)

set "output=x:\somewhere\myFile.dat"
wget -O "%output%" "http://somewhere.com/this" || ( 2>nul del "%output%" )

note: Of course, you don't need the variable, just included to avoid having to write the same file name in both commands.

Upvotes: 1

Related Questions