Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So far I run a .bat file to find all the media files stored on our student shared drive, which then writes to a .txt file in my documents, for example:

dir S:*.mp3 /s > "M:\logs\student\mp3.txt"

This is probably not the best way of doing it and I am aware there are probably better tools in 2008 R2 to do this for me. I am now trying to find a way to only log files that are, for example, bigger then 100mb. Is this doable in a .bat files/cmd.exe, am I better off using PowerShell, or use the fuctions in Server 2008R2?

share|improve this question
up vote 1 down vote accepted
@echo off
rem only files bigger than %threshold% MB are listed
set threshold=100

for /r %%F in (*) do call :foo %%~zF "%%F"
goto :eof

set size=%1
set size_mb=%size:~0,-6%
if not defined size_mb set size_mb=0
if %size_mb% GTR %threshold% echo.%~2
goto :eof

The subroutine is sadly necessary since delayed expansion didn't want the way how I extracted the megabytes (yes, indeed, megabytes, not mebibytes – I don't like it either, but it's the easiest here).

Note that this approach will fail for files larger than roughly two exabytes since cmd cannot do a numeric comparison with values that won't fit into a signed 32-bit integer.

The code can also be found in my SVN repository.

share|improve this answer
chuckle Thanks, although if a student has 1 million terabytes worth of stuff I think we'd notice long before me using this. – tombull89 Nov 9 '10 at 13:58

You're better off using find.

share|improve this answer

PowerShell or VBScript are the way to go. I've tried what you're doing with Shell script, and you end up doing a lot of for() and findstr calls, stripping commas from sizes, Etc.

VBScript has the FileSystemObject - do a google.

PowerShell has get-childitem:

Get-childitem -LiteralPath <basepath> -Filter *.mp3 -recurse -erroraction silentlycontinue | where-object{ $_.length -gt 100MB }

The above scans the path <basepath> and all subdirs for MP3s > 100MB.

You can then add to the "pipeline":

| foreach-object{ //dosomething }

The powershell on-line help is very good; try: get-help get-childitem -detailed for example.

Happy scripting!

Oh, and don't forget that Win2k8 has "File Server Resource Manager" - a great tool.

share|improve this answer
Besides, you may want to use an actual PowerShell comment instead of a C++ one ;-) – Joey Nov 9 '10 at 12:08
C++ ? Confused, I am. – Simon Catlin Nov 9 '10 at 20:17
You've given the code snippet | foreach-object{ //dosomething } which – for PowerShell – might read | foreach-object{ <# dosomething #> }. At least I thought it to be customary to use the language's own comment marker for such things ;) – Joey Nov 9 '10 at 21:17
Ah. Point taken. You're more of a pedant than me (and that's saying something!) ;-) – Simon Catlin Nov 9 '10 at 21:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.