Batch file to delete a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Wolfy
Posts: 2
Joined: 17 Mar 2017 03:36

Batch file to delete a file

#1 Post by Wolfy » 12 Jun 2017 09:08

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file to delete a file

#2 Post by aGerman » 12 Jun 2017 10:51

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

Post Reply