Page 1 of 1

Adapting file size to current 'list all files in directory' script

Posted: 09 Jul 2016 15:11
by SIMMS7400
Hi Folks -

I have a script that lists all files in a directory tree with path, file name, size, and owner. Is there an easy way to add something that says only list files over a certain size?

For instance, 100mb?

Code: Select all

@ECHO OFF
SetLocal EnableDelayedExpansion
for /r %%a in (*) do for /f "tokens=5" %%b in ('dir /q "%%~fxa" ^| findstr "%%~nxa"') do (
    echo "%%~dpa","%%~nxa","%%~za","%%b"
) >> LIST_ALL_FILES_INFO.csv


Thank you!

Re: Adapting file size to current 'list all files in directory' script

Posted: 09 Jul 2016 15:49
by aGerman
100 MB are 104857600 Bytes.

Code: Select all

if %%~za gtr 104857600 echo ...


Regards
aGerman

Re: Adapting file size to current 'list all files in directory' script

Posted: 09 Jul 2016 17:04
by Compo
SIMMS7400 wrote:

Code: Select all

@ECHO OFF
SetLocal EnableDelayedExpansion
for /r %%a in (*) do for /f "tokens=5" %%b in ('dir /q "%%~fxa" ^| findstr "%%~nxa"') do (
    echo "%%~dpa","%%~nxa","%%~za","%%b"
) >> LIST_ALL_FILES_INFO.csv

I may be wrong here but:

Code: Select all

19/08/2015  23:41                64 BUILTIN\Administrators Scan to PC.url
02/07/2016  23:54    <DIR>          Aurora-R4-3820\Compo   Scripts
In the case of both files and directories the fourth token is the Owner information

Re: Adapting file size to current 'list all files in directory' script

Posted: 09 Jul 2016 20:48
by SIMMS7400
aGerman -

Thanks, works like a charm! SImple too, I should have thought of that!

Compo -

COrrect.

Output is as follows:

Path,file name,size,owner

Re: Adapting file size to current 'list all files in directory' script

Posted: 10 Jul 2016 18:03
by foxidrive
It'll work up to 2gb files anyway, which is where batch math bombs out.

Re: Adapting file size to current 'list all files in directory' script

Posted: 10 Jul 2016 18:56
by penpen
If it is above 2GB then you could prepend for example 20 zeroes, and shorten the string to 20 digits:

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
::     0123456789001234567890
set "x=9999999999999999"
set "y=9999999999999999"


set "_x=00000000000000000000!x!"
set "_y=00000000000000000000!y!"
set "_x=!_x:~-20!"
set "_y=!_y:~-20!"

if "a!_x!" lss "a!_y!" (
   echo !x! lss !y!
) else if "a!_x!" gtr "a!_y!" (
   echo !x! gtr !y!
) else (
   echo !x! equals !y!
)

endlocal
goto :eof


penpen