Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Finding files bigger than X

    I wrote this to find files bigger than 5000 but the output only almost works.
    Code:
    @echo off
    for /f "skip=5 tokens=1-6" %%A IN ('dir /-C /O:-S /T:C /Q') do (
    echo %%D   %%F
       if NOT "%%D" EQU "bytes" (
          if /I "%%D" GTR "5000" (
             echo %%A %%B %%C %%D %%E %%F
          )
       )
    )
    The output is:
    Code:
    794452   bys.pdf
    01/04/2015 03:16 PM 794452 san\wir bys.pdf
    12141   est.txt
    9538   blg
    01/15/2015 10:08 PM 9538 san\wir blg
    8355   nds.bat
    12/24/2014 11:41 PM 8355 BUILTIN\Administrators nds.bat
    8237   nds.txt
    12/28/2014 11:29 PM 8237 san\wir nds.txt
    7366   et.bat
    01/02/2015 10:21 PM 7366 BUILTIN\Administrators et.bat
    3973   vt.txt
    3789   vt.bat
    2879   erob.txt
    2653   ecur.txt
    2231   ekr.txt
    2057   loginMon.txt
    1980   dirl
    1144   fndLgFil.bat
    1143   fndLgFil.txt
    779   eistOf.txt
    01/04/2015 08:19 PM 779 san\wir eistOf.txt
    583   endr.bat
    01/02/2015 12:28 AM 583 BUILTIN\Administrators endr.bat
    490   nlst
    427   tvD.txt
    It starts out kinda OK but drops est.txt. Then continues OK until it got to eistOf.txt and endr.bat which I should not be displaying since the size is <5000.
    Does someone see where this fails? I was beginning to think I was getting better at batching. Thanks!!
    Last edited by RetiredGeek; 2015-01-18 at 23:34. Reason: Fixed code tags

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Spark,

    Take out the quotes in the comparison line {you're not comparing strings but numbers}:
    Code:
       if /I %%D GTR 5000 (
    My Test Output:
    Code:
    5012   TEDsCleanup.pdf
    01/01/2014 12:55 AM 5012 BUILTIN\Administrators TEDsCleanup.pdf
    4399   Dell
    1344   TEDsCleanup.cmd
    849   UniversalDateTImeCommands.cmd
    702   RebuildIconCache.cmd
    696   RebuildIcons.cmd
    539   Test.cmd
    364   SSD-Align.VBS
    207   TestSize.cmd
    205   TimedRestart.cmd
    203   CopyAndRenameWithDateTime.cmd
    193   Testparms.cmd
    144   TimedRestartFinished.cmd
    79   BTBFileListing.CMD
    78   Batch1.cmd
    22   Batch2.cmd
    <DIR>   ..
    <DIR>   BackupTasks
    <DIR>   .
    bytes   
    bytes
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,162
    Thanks
    47
    Thanked 976 Times in 906 Posts
    Treesize free will list files by size in a folder - it even prints nice reports.

    cheers, Paul

  4. #4
    WS Lounge VIP access-mdb's Avatar
    Join Date
    Dec 2009
    Location
    Oxfordshire, UK
    Posts
    1,720
    Thanks
    146
    Thanked 156 Times in 149 Posts
    But Paul, it appears that the OP wants files over a certain size, not all files.

  5. #5
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,162
    Thanks
    47
    Thanked 976 Times in 906 Posts
    Just offering an option that may work for some.

    cheers, Paul

  6. #6
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts
    @RG: Big thanks. Made it work but the dir + if's takes WAY-WAY too long >10 min/drive.
    One thing tho
    if /? states:
    and the /I switch, if specified, says to do case insensitive string compares.
    ... These comparisons are generic, in that if both string1 and string2 are both comprised of all numeric digits, then the strings are converted to numbers and a numeric comparison is performed.

    How then are the strings I created with double quotes not all treated as numeric?
    Last edited by spark55; 2015-01-20 at 04:48.

  7. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Spark,

    That is true as specified here.

    However, that would appear to be incorrect! If you look at your results you can see it is clearly doing an string comparision, i.e., character by character left to right thus the file size of 779 (which would be greater than 5000 - 7>5) showing up in the list. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  8. #8
    New Lounger
    Join Date
    Dec 2009
    Location
    Columbia, Maryland, USA
    Posts
    9
    Thanks
    2
    Thanked 1 Time in 1 Post
    If you have some spare time to do some studying, take a look at Windows PowerShell. It's like batch files on steroids. I'm just getting started with it, but it can probably do what you want in just a few seconds.

    Pat

  9. #9
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Pat,

    I thought nobody would ask.

    PS Code:
    Code:
    <#+----------------------------------------------------------------------+
      | Function     : Get-FilesLargerThan                                   |
      | Description  : Retrieve files greater than specified size            |
      | Programmer   : RetiredGeek (WSL) aka: ComputerMentor                 |
      | Created      : 22 Jan 2015                                           |
      | Last Updated :                                                       |
      | Current Vers : 1.0                                                   |
      +----------------------------------------------------------------------+
    #>
    param (
            [Parameter(Mandatory=$true)]
              [String]$FileSpec,
            [Parameter(Mandatory=$true)]
              [Long]$MinFileSize
    )
    Clear-Host
    
    $listfmt = @{Expression={$_.CreationTimeUTC};Label="Created";width=22},
               @{Expression={$_.Length};Label="Length";width=8},
               @{Expression={$_.Owner};Label="Owner";width=25},
               @{Expression={$_.Name};Label="File Name";width=75}
    
    #Code to adjust default output console width!
    if( $Host -and $Host.UI -and $Host.UI.RawUI ) {
     $rawUI = $Host.UI.RawUI
     $oldSize = $rawUI.BufferSize
     $typeName = $oldSize.GetType( ).FullName
     $newSize = New-Object $typeName (500, $oldSize.Height)
     $rawUI.BufferSize = $newSize
    }
    
     Get-ChildItem "$FileSpec" |
       Where-Object {$_.Length -gt $MinFileSize} |
       Select-Object CreationTimeUTC, Length, 
         @{Expression={$_.GetAccessControl().owner};Label="Owner"}, Name |   
       Format-Table $listfmt
    Calling Sequence: Get-FilesLargerThan.ps1 "G:\BEKDocs\Excel\VBA\*.txt" 5000 > "G:\BEKDocs\FLTest.text"

    Note: if working in PS console you can drop the redirect to file part.

    Output:

    I had some really long file names so I had to include some code to change the default console size!
    Code:
    Created                  Length Owner                     File Name                                                                  
    -------                  ------ -----                     ---------                                                                  
    10/25/2013 1:11:37 AM      8673 DellXPS8700\Bruce         VBA - Excel - Generalized Text Box Numerical Entry Checker .txt            
    10/25/2013 1:11:38 AM      5742 DellXPS8700\Bruce         VBA - Excel - Print to PDFCreator Examples.txt
    Interesting Note: I had one file in the searched directory that showed as 5Kb however it didn't show in the list! I reduced the threshold to 4000 and the file showed up with an actual size of 4661. Moral, you can't trust the sizes in File Explorer!

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  10. #10
    2 Star Lounger
    Join Date
    Aug 2014
    Posts
    123
    Thanks
    19
    Thanked 0 Times in 0 Posts
    GEEE!! This has been a lot of help.
    I moved over to Unix after 98 and have this weird idea that superstructuring of languages to object orientation totally misses the point of languages like DOS/BATCH, Classic C, Basic, bash, and such. They are quick, simple and direct proviso one knows how to use them.
    Adding object orientation has only served the managers that can barely read it and like to pontificate on ease of modes, no need to retrain, etc, ad nauseum. Anyway I'll stick with bash and finish with the trek into Batch refresh. Here is what I found for finding bigger than:
    for /R "%DIRNAM%" %%F in (*) do (
    if exist "%%F" if %%~zF GEQ %MXSIZ% echo %%~zF %%F
    )
    Where MXSIZ is my upper limit in C:/D:/E: whatever fir DIRNAM. Been flue ridden for a week so hope that line makes sense cuz I cut it from where I remember being.

  11. #11
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    Spark,

    To each his own! I've programmed and taught more languages than I want to remember and I'll always prefer to work in a language where I can look at the code 6 months after I wrote it and at a glance know what it does, especially at my advanced age! It's also why I comment my code so much.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •