Page 1 of 1

Batch file to delete a file

Posted: 12 Jun 2017 09:08
by Wolfy
I run a mapping tool to convert a flat file into a CSV file.

I run this job every 20 minutes.

When there is a file to convert it works great and produces exactly what I need. Example below.


All Rounds / Franchises,,,,,
12/06/2017,,,,,
Delivery Date,Customer,Reference,Item,Description,Quantity
13/06/17,COOP019,23327-A-054,R016,Cheese Topped Roll 4s,4
13/06/17,COOP019,23327-A-054,R012,Cheese Scones 3s,3
13/06/17,COOP019,23327-A-054,R009,Fruit Scones 3s,2

However if there isn't anything to convert it still tries to create a file but it just creates the headers of the file and no lines.

All Rounds / Franchises,,,,,
12/06/2017,,,,,
Delivery Date,Customer,Reference,Item,Description,Quantity



So I am sending out files to suppliers that don't actually have any meaningful data in them.

So what I'm looking for is a batch file to be able to see if there is any data on the 4th line and if not to delete it/move it elsewhere.

Any ideas?

Cheers
Wolfy

Re: Batch file to delete a file

Posted: 12 Jun 2017 10:51
by aGerman
untested ...

Code: Select all

@echo off &setlocal
set "data="
for /f "usebackq skip=3" %%i in ("your file.csv") do set "data=1"
if not defined data ECHO del "your file.csv"
PAUSE


If that displays the file to delete just remove ECHO and PAUSE.

Steffen