I need to compare two sets of folder information

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
arestas
Posts: 5
Joined: 09 Apr 2015 08:14

I need to compare two sets of folder information

#1 Post by arestas » 09 Apr 2015 08:21

Hello,
Iam new around and in the batch scripting world. iam having some issues to create a simple script to extract a value from a output i have.
Output similar to:
Files: 193368
Directories: 1003
Size: 5,459,286,921,170 bytes
Size on disk: 5,459,693,432,960 bytes

i want to take the value of the "Size" inside a variable so i can compare it. Problem is that ive made a few tries and didnt make it.
Was close to get it with:
for /f "tokens=2 skip=2 delims= " %%i in (file.txt) do echo [%%i]

but it returns me

[5,459,286,921,170]
[on]
...
and i cant move from here...

Can anyone give me and hand with this please.

Regards,

Arestas

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help with simple program

#2 Post by foxidrive » 09 Apr 2015 09:29

The task as you specify is simple enough, but you can't do a numerical compare with values over 2 GB using plain batch code.

If you reveal the actual task then one of us can waste their time to help you solve it.

arestas
Posts: 5
Joined: 09 Apr 2015 08:14

Re: Need some help with simple program

#3 Post by arestas » 09 Apr 2015 10:29

Well, iam copying files from one file server to another using a robocopy script.
What i pretend is to compare source and destination by size. if they are the same send an email saying "task ended" and if they are not send a email saying "check folder".

To compare sizes iam using a batch script that will run when scripts ends that will call a windows tool called du. it will output the result to a *txt file with the following format:
Files: 193368
Directories: 1003
Size: 5,459,286,921,170 bytes
Size on disk: 5,459,693,432,960 bytes

So i now need to treat this output in order to get size of folder1 and folder2 and compare both.

Regards,

Arestas

arestas
Posts: 5
Joined: 09 Apr 2015 08:14

Re: Need some help with simple program

#4 Post by arestas » 09 Apr 2015 11:21

Iam moving some fileshare for new servers. For that iam using a robocopy script.

what i wanna implement is some kind of automatic validation. So i ve created a script to to check folder size at source and at destination using a windows tool called du.
That script will write 2 text files with the output you can see in the first post.

So now that i have the size of the source folder and destination folder i wanna compare them to send an alert email.

My problem is just to extract the size from the output, so i can compare them and create the alerts.

If i wasn't clear enough feel free to ask for more info.

Regards,

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help with simple program

#5 Post by foxidrive » 09 Apr 2015 22:14

arestas wrote:To compare sizes iam using a batch script that will run when scripts ends that will call a windows tool called du. it will output the result to a *txt file with the following format:
Files: 193368
Directories: 1003
Size: 5,459,286,921,170 bytes
Size on disk: 5,459,693,432,960 bytes


A simple way is to compare the two outputs of DU if they show as your example above appears.

Another way is to check the errorlevel result of robocopy to see if there were any failures.

Further information about the task or DU output would be useful.

arestas
Posts: 5
Joined: 09 Apr 2015 08:14

Re: Need some help with simple program

#6 Post by arestas » 10 Apr 2015 02:48

i would like to compare DU result, but only by the Size.
Any ideas on how can i extract only the value of the size from the 2 output files and compare them?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need some help with simple program

#7 Post by foxidrive » 10 Apr 2015 06:20

This is not the only way to do it - just one way.

Code: Select all

@echo off
type du1.txt|find "Size: ">"file1.txt"
type du2.txt|find "Size: ">"file2.txt"
fc /b "file1.txt" "file2.txt" >nul || echo send email coz stuff happened
del file?.txt

arestas
Posts: 5
Joined: 09 Apr 2015 08:14

Re: Need some help with simple program

#8 Post by arestas » 10 Apr 2015 07:29

Tanks for all the foxidrive.

It works like a charm.

Regards,

Arestas

Post Reply