Batch File to check two files sizes

June 24, 2009 at 10:16:46
Specs: Windows 2K/XP
I'd like to check if two files (one on server path and another local) have the same size and if they don't then copy the content of the whole folder containing the server file to replace the content of the folder containing the local file.
Can anyone do that ?

See More: Batch File to check two files sizes

Report •


#1
June 24, 2009 at 11:05:01
@echo off & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in ('dir/b servfile locfile') do (
set %%~Na=%%~Za
)
if !servfile! gtr !locfile! copy blabla


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
June 24, 2009 at 11:21:10
cheers that was impressively fast
would you mind telling what I need to modify
I assume servfile would be my server file Z:\4D.VER
and locfile would be my local file C:\4D.VER

so would the final batch be :

@echo off & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in ('dir/b Z:\4D.VER C:\4D.VER') do (
set %%~Na=%%~Za
)
if !Z:\4D.VER! gtr !C:\4D.VER! xcopy Z:\ c:\ /s

I cannot get it to work though, would it also work if file size of server file is smaller ?


Report •

#3
June 24, 2009 at 11:37:09
[1] Since the file names are the same it will take a bit more doing.

[2] Copying to the root, c:\, sounds like trouble in the making.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
June 24, 2009 at 13:08:19
@echo off & setLocal enableDELAYedexpansion

pushd d:\
for /f "tokens=* delims= " %%a in ('dir/b myfile.txt') do (
set Dsize=%%~Za
)

pushd c:\
for /f "tokens=* delims= " %%a in ('dir/b myfile.txt') do (
set Csize=%%~Za
)

echo if !Dsize! gtr !Csize! copy d:\ c:\


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
June 25, 2009 at 00:32:36
Well it's not actually on the root of each drives,
the full path is Z:\4D\Server\check.txt for the server file
and C:\4D\Client\check.txt for the local file
so I modified your script like this removing the last echo for the line to work :

@echo off & setLocal enableDELAYedexpansion

pushd z:\
for /f "tokens=* delims= " %%a in ('dir/b 4d\server\check.txt') do (
set Dsize=%%~Za
)

pushd c:\
for /f "tokens=* delims= " %%a in ('dir/b 4d\client\check.txt') do (
set Csize=%%~Za
)

if !Dsize! gtr !Csize! copy z:\4D\server c:\4d\client

but still it does not work for me, any idea why ?


Report •

#6
June 25, 2009 at 00:41:52
You need to push the the containing directory. Try this:

===============================
@echo off & setLocal enableDELAYedexpansion

pushd z:\4D\Server
for /f "tokens=* delims= " %%a in ('dir/b check.txt') do (
set Zsize=%%~Za
)

pushd c:\4D\Client
for /f "tokens=* delims= " %%a in ('dir/b check.txt') do (
set Csize=%%~Za
)

if !Zsize! gtr !Csize! copy z:\4D\server c:\4d\client


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#7
June 25, 2009 at 01:44:48
Many thanks for your help ! Works like a charm

Report •


Ask Question