Windows – How to use robocopy to list all files over a certain size recursively

robocopywindows

I feel quite silly, since robocopy is server administration 101; but I seem to be having a problem listing files.

I desire to list all files over 10MB in size in the directory and subdirectory.

According to docs, this is what should work:

robocopy c:\ /min:10485760 /s /l /fp /tee /log:c:\robocopy.log /njh /njs /ndl

But when I run it, an error is returned "No Destination Directory Specified," which I think isn't needed if you are using the list (/L) option.

Also, if I include the same directory as the destination like so:

robocopy c:\ c:\ /min:10485760 /s /l /fp /tee /log:c:\robocopy.log /njh /njs /ndl

Nothing is returned; but if I drop the no directory list (/ndl), I see a list of all directories.

So my question is: How do I use robocopy to list files over 10MB in a directory tree structure, and just that?

Thanks!

Best Answer

If you're not tied to robocopy, you can achieve this with using for's variable substitution:-

@for /f "tokens=*" %F in ('dir /s /b /a:-d c:\') do @(
    if %~zF geq 10485760 echo %F
)

dir /s /b /a:-d c:\ gives you a recursive listing (/s) of all non-directories (/a:-d) under c:\ in bare format (/b) for easier parsing.

for loops over that listing ("tokens=*" is needed in case you have paths with spaces in them), and let's you get the reference the file's size using its ~z variable modifier in any sub-commands (like if to compare against the size you want).

The @'s are to suppress echoing of the commands, and can be omitted if you've called @echo off previously (e.g., in a batch file).