Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

DOS CMD Help

Thread Tools
 
Search this Thread
 
Old 28 April 2009, 12:08 PM
  #1  
Avi
Scooby Regular
Thread Starter
 
Avi's Avatar
 
Join Date: Apr 2001
Location: Manchester
Posts: 5,084
Likes: 0
Received 0 Likes on 0 Posts
Default DOS CMD Help

I have a .bat file which contains the following command

copy /y "d:\downtime\report.htm" "\\server55\downtime\folder2"

The htm file is recreated every 10 minutes but occasionally the htm file is corrupted and has a filesize of 0, if this occurs i would like to prevent it being copied. Can anyone suggest how i might write something into the batch file to only copy the file of filesize is greater than 0 ?

Any advice appreciated

Cheers

Andy
Old 28 April 2009, 12:22 PM
  #2  
HankScorpio
Scooby Regular
 
HankScorpio's Avatar
 
Join Date: Feb 2004
Posts: 5,848
Likes: 0
Received 0 Likes on 0 Posts
Default

Something like:

FORFILES /P d:\downtime /M report.txt /C "cmd /c if @fsize GEQ 0 copy /y @file \\server55\downtime\folder2"

An extra exit would be needed to end the extra CMD session.

But that's off the top of my head, test it thoroughly!!
Old 28 April 2009, 12:58 PM
  #3  
LostUser
Scooby Regular
 
LostUser's Avatar
 
Join Date: Oct 2005
Posts: 476
Likes: 0
Received 0 Likes on 0 Posts
Default

This command will return the length of the file.

So rather than echo %length%, use the parameter to check if length is 0

for %%a in (report.htm) do (
set length=%%~za
)
echo %length%
Old 28 April 2009, 01:20 PM
  #4  
Avi
Scooby Regular
Thread Starter
 
Avi's Avatar
 
Join Date: Apr 2001
Location: Manchester
Posts: 5,084
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by HankScorpio
Something like:

FORFILES /P d:\downtime /M report.txt /C "cmd /c if @fsize GEQ 0 copy /y @file \\server55\downtime\folder2"

An extra exit would be needed to end the extra CMD session.

But that's off the top of my head, test it thoroughly!!
This has done the job perfectlt - you are da man!

Thanks to you LostUser also.. that may come in useful too.
Old 28 April 2009, 01:57 PM
  #5  
HankScorpio
Scooby Regular
 
HankScorpio's Avatar
 
Join Date: Feb 2004
Posts: 5,848
Likes: 0
Received 0 Likes on 0 Posts
Default

Cool but just realised it should be "GEQ 1" or would also copy a zero size file.
Old 28 April 2009, 02:26 PM
  #6  
Avi
Scooby Regular
Thread Starter
 
Avi's Avatar
 
Join Date: Apr 2001
Location: Manchester
Posts: 5,084
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by HankScorpio
Cool but just realised it should be "GEQ 1" or would also copy a zero size file.
Yeah i did realise that when i tested it. Cheers again.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Darrell@Scoobyworx
Trader Announcements
26
30 January 2024 01:27 PM
blackieblob
ScoobyNet General
4
01 October 2015 11:37 AM
alcazar
Non Scooby Related
37
27 September 2015 10:35 PM
StueyBII
General Technical
4
26 September 2015 12:35 PM



Quick Reply: DOS CMD Help



All times are GMT +1. The time now is 11:42 PM.