Folder located at remote machine

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
smeru
Posts: 5
Joined: 17 Dec 2013 04:39

Folder located at remote machine

#1 Post by smeru » 17 Dec 2013 04:53

Hi,

This is my first post in this forum.

I want to find the size of a folder located at remote machine from a batch command like the size which we see when we right click a folder and see its properties "Size on disk"

Is this possible ?

Thanks,
Srini

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

Re: Folder located at remote machine

#2 Post by foxidrive » 17 Dec 2013 05:48

One folder shows this here: 824 KB (843,776 bytes)

Which number are you after, the real base 10 figure or the power-of-2 figure?

smeru
Posts: 5
Joined: 17 Dec 2013 04:39

Re: Folder located at remote machine

#3 Post by smeru » 17 Dec 2013 06:13

I want only 824 KB

I hope you understand me.

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

Re: Folder located at remote machine

#4 Post by foxidrive » 17 Dec 2013 06:27

This is simple code to provide the base 10 figure.

Code: Select all

@echo off
set "folder=\\server\share\foldername"
for /f "tokens=3 delims= " %%a in ('dir "%folder%" /s^|find " File(s) "') do set foldersize=%%a
echo "%folder%" is %foldersize%


Batch math tops out at 2GB but this will display larger figures.

To get the base 2 figure you will need a VBS script or a powershell script.

smeru
Posts: 5
Joined: 17 Dec 2013 04:39

Re: Folder located at remote machine

#5 Post by smeru » 17 Dec 2013 06:47

Its giving the result in bytes only. Just now tried with a folder having size of 1.5 GB. The result should come as 1.5 GB.

What if the folder size is more than 2 GB ? How can I use powershell scripting ? Could you please guide me ?

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

Re: Folder located at remote machine

#6 Post by foxidrive » 17 Dec 2013 06:57

This will give you a GB figure - it's not versatile so it just returns GB

Code: Select all

@echo off
set "folder=\\server\share\foldername"
for /f "tokens=3 delims= " %%a in ('dir "%folder%" /s^|find " File(s) "') do set foldersize=%%a
echo Wscript.echo Formatnumber(eval(WScript.Arguments(0)/1073742268), 2, True,, False) > "%temp%\Calculate.vbs"
for /f "delims=" %%a in ('cscript //nologo "%temp%\Calculate.vbs" "%foldersize%" ') do set GB=%%a&del "%temp%\Calculate.vbs"
echo "%folder%" is %GB% GB (%foldersize%)
pause

smeru
Posts: 5
Joined: 17 Dec 2013 04:39

Re: Folder located at remote machine

#7 Post by smeru » 17 Dec 2013 09:20

Now its not showing the correct data in MBs and KBs

Code should auto calculate the folder size and append the suffix like KB,MB or GB appropriately.

smeru
Posts: 5
Joined: 17 Dec 2013 04:39

Re: Folder located at remote machine

#8 Post by smeru » 18 Dec 2013 02:58

Is it possible by any chance ?

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

Re: Folder located at remote machine

#9 Post by foxidrive » 18 Dec 2013 03:19

You have to write the VBS script to rearrange the numbers, it's not a built in function.

Post Reply