Directory Size?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Yamanipanuchi
Posts: 6
Joined: 17 Aug 2012 15:32

Directory Size?

#1 Post by Yamanipanuchi » 01 Oct 2012 11:49

Was wondering if anyone out there know a better way to do this?

@echo off

for /f "tokens=2 delims= " %%a in ('date /T') do (set date=%%a)
for /f "tokens=1,2 delims= " %%b in ('time /T') do (set time=%%b)

pushd "R:\"
for /f "tokens=3 delims= " %%e in ('dir /s /w ^| find /i "File(s)"') do (set dept_dir_size=%%e)
popd

echo %date% %time% - Department - %dept_dir_size%
echo %date% %time% - Department - %dept_dir_size% >> c:\List.txt

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

Re: Directory Size?

#2 Post by foxidrive » 01 Oct 2012 12:35

This will give you a more accurate file count but it will only count all files on the drive that the user account has permissions to list.

Code: Select all

@echo off
dir R:\ /b /s /a-d 2>nul >%temp%\files.txt
for /f "delims=" %%e in ('find /c /v "" ^<%temp%\files.txt') do (
echo %date% %time% - Department - %%e
>>c:\List.txt echo %date% %time% - Department - %%e
)
del %temp%\files.txt
pause

Yamanipanuchi
Posts: 6
Joined: 17 Aug 2012 15:32

Re: Directory Size?

#3 Post by Yamanipanuchi » 01 Oct 2012 12:51

I realized after the fact that I didn't really make it clear what I was trying to do. I'm trying to get the size of the directory including all the sub directories.

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

Re: Directory Size?

#4 Post by foxidrive » 01 Oct 2012 12:58

Drive size minus freespace?

Yamanipanuchi
Posts: 6
Joined: 17 Aug 2012 15:32

Re: Directory Size?

#5 Post by Yamanipanuchi » 01 Oct 2012 15:31

Ya, that work normally. This is unfortunately a Network share and the share is not the root of all the folders.

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

Re: Directory Size?

#6 Post by foxidrive » 01 Oct 2012 16:21

This is similar to your technique but should be faster on large subdirectories.

Code: Select all

@echo off
dir r:\ /s /a-d 2>nul >%temp%\files.txt
for /f "tokens=3" %%e in ('find /i "File(s)" ^<%temp%\files.txt') do set total=%%e
echo %date% %time% - Department - %total%
>>c:\List.txt echo %date% %time% - Department - %total%
del %temp%\files.txt

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

Re: Directory Size?

#7 Post by aGerman » 01 Oct 2012 16:25

@Yamanipanuchi
The size of a folder is nowhere saved. Try to display the properties of the Windows folder in your explorer window. It takes some time to get the number of files / folders and the folder size. That means it loops recursively across the folder to collect the data step by step. That's the same like DIR /S does. I assume there is no better way.

Regards
aGerman

Post Reply