0

Hard drives are big these days and I want to store all my pictures on it and some times check to see if I have added or moved any files out by mistake.

this one is the one that works close to what I need but I don't what it to show me all the folders, just my selected ones

How to list all folder with size via batch file

I need a simple Batch file that can do a byte count and compare it to a number that it should be echo, good or not and then same routine on my chosen folder.. thanks for the help in advance

set "folder=DVD-001 - 4,471,234,796" 

set "size=0

for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\

@echo foldername  !size! Bytes

IF !size! EQU 4471234796 (@echo good) ELSE (@echo oops)

:next folder

set "folder=DVD-002 - 4,590,775,746"

set "size=0

for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\

@echo foldername  !size! Bytes

IF !size! EQU 4590775746 (@echo good) ELSE (@echo oops)  
Community
  • 1
  • 1

1 Answers1

0
  • Comparing to the predefined list of folders with sizes:

    @echo off
    setlocal enableDelayedExpansion
    
    for /f "delims=: tokens=1,2*" %%a in ('^
        echo DVD-001: 4471234796: f:\folder1 ^&
        echo DVD-002: 4590775746: d:\another folder ^&
        echo DVD-003: 1111111111: e:\folder 3 ^&
        echo DVD-004: 2222222222: c:\folder 4 ^
    ') do (
        set status=
    
        rem trim the path
        for /f "tokens=*" %%c in ("%%~c") do set folder=%%~c
        for /l %%c in (1,1,100) do if "!folder:~-1,1!"==" " set folder=!folder:~0,-1!
        for /l %%c in (1,1,100) do if "!folder:~-1,1!"=="\" set folder=!folder:~0,-1!
    
        rem trim dvd size
        for /f %%b in ("%%~b") do set dvdsize=%%~b
    
        rem get folder size
        set size=
        if exist "!folder!" (
            rem save penultimate line
            for /f "tokens=2,3*" %%s in ('dir "!folder!" /s /w /a 2^>^&1') do (
                set prev=!cur! & set cur=%%t
            )
            rem combine digit groups
            for /l %%s in (0,1,20) do (
                if "!prev:~%%s,1!" geq "0" if "!prev:~%%s,1!" leq "9" (
                    set size=!size!!prev:~%%s,1!
                )
            )
        ) else (
            set size=NOT FOUND
        )
        if !size!==!dvdsize! (
            echo GOOD %%a: !dvdsize! == !folder!
        ) else (
            if "!size!"=="" set size=ERROR
            echo OOPS %%a: !dvdsize! ^<^> !size! !folder!
        )
    )
    pause
    
  • A two-way robocopy in list-only mode would be more reliable in case both folders exist:

    @echo off
    set DIR1=d:\somefolder (no trailing slash!)
    set DIR2=e:\anotherfolder (no trailing slash!)
    robocopy /L /njh /njs /ndl /s "%DIR1%" "%DIR2%" | find "%DIR1%"
    if errorlevel 1 (
        robocopy /L /njh /njs /ndl /s "%DIR2%" "%DIR1%" | find "%DIR2%"
        if errorlevel 1 (echo GOOD & goto DONE)
    )
    echo OOPS
    :DONE
    pause
    

    It will list the different files as well.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • This program works great for comparing 2 folders but what I have is a folder and a known Byte count that it should be, I don't have 2 folders to compare. I need the program to compare a folder to a Byte a number. – Sonicdreams Jul 23 '15 at 15:27
  • Thanks wOxxOm I do have a use for two-way robocopy as well and have already found it usefull. – Sonicdreams Jul 23 '15 at 15:39
  • OOPS DVD-001 - Mirror <> 4471234796 OOPS DVD-002 - Mirror <> 4590775746 OOPS DVD-003 - Mirror <> 1111111111 OOPS DVD-004 - Mirror <> 2222222222 Press any key to continue . . . this is all I get one and 2 should be right , also I am not sure how to direct it to the folder such as f:\folder1 or d:\dvd-folder6 – Sonicdreams Jul 23 '15 at 23:01
  • Ah, little by little you expose more details that should have been present in the question :-) I've updated the code. – wOxxOm Jul 24 '15 at 05:37
  • Sorry I was not clear on what I meant and sorry I just can't get it to work, maybe it will not work on windows XP or maybe my robocopy Ver. XP010 is the problem. All I get is ( OOPS DVD-001 - Mirror <> 4471234796 ) even if the FOLDER DVD-001 is the correct size or not. I have tried using other folder names like c:\test as well. I have tried with all in the root of c: and no different. Just to be clear all are folders are on the hard drive none of them are using a CD or a DVD drive. why does it show me the word Mirror? – Sonicdreams Jul 24 '15 at 18:17
  • Well, maybe robocopy on XP prints different info, so I've updated the code to look for the word `Bytes` in robocopy statistics which is, alas, locale-specific. However it's still better than `dir /s` that would require several runs to count hidden/system files. – wOxxOm Jul 24 '15 at 18:57
  • Try running `robocopy /njh /ndl /nfl /s /is /l /bytes . .` manually and see if it prints the summary with "Bytes : 123456" – wOxxOm Jul 25 '15 at 05:59
  • C:\>robocopy c:\DVD-001 /njh /ndl /nfl /s /is /l bytes:123456 ------------------------------------------------------------------------------ Total Copied Skipped Mismatch FAILED Extras Dirs : 156 156 0 0 0 0 Files : 9009 9009 0 0 0 0 Bytes : 4.164 g 4.164 g 0 0 0 0 Times : 0:00:00 0:00:00 0:00:00 0:00:00 Ended : Sat Jul 25 08:22:21 2015 ----- yes that folder has 9009 files – Sonicdreams Jul 25 '15 at 15:22
  • with out putting the 123456 at the end it still runs the same, Bytes : 4.164 g 4.164 g – Sonicdreams Jul 25 '15 at 15:31
  • Why did you put `bytes:123456` to the command line? It's just a sample what to look for in the summary. Please run the command exactly as I typed. – wOxxOm Jul 25 '15 at 16:24
  • robocopy /njh /ndl /nfl /s /is /l /bytes . . ERROR : Invalid Parameter #7 : "/bytes" – Sonicdreams Jul 25 '15 at 17:50
  • WOW ! it works great and have already found one of my folders had dropped 2 of my files (filenames too long).. I TB drive tested, 5 more TB to go. After it found the problem I ran the (2-way robocopy) found it & fixed it. Thank you for your hard work and your patience with me. THANKS! – Sonicdreams Jul 26 '15 at 05:39