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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

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

#1 Post by SIMMS7400 » 09 Jul 2016 15:11

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!

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

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

#2 Post by aGerman » 09 Jul 2016 15:49

100 MB are 104857600 Bytes.

Code: Select all

if %%~za gtr 104857600 echo ...


Regards
aGerman

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

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

#3 Post by Compo » 09 Jul 2016 17:04

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

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

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

#4 Post by SIMMS7400 » 09 Jul 2016 20:48

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

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

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

#5 Post by foxidrive » 10 Jul 2016 18:03

It'll work up to 2gb files anyway, which is where batch math bombs out.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

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

#6 Post by penpen » 10 Jul 2016 18:56

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

Post Reply