Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Hi all - trying to count files in a folder and pass it to a var can you help  (Read 3398 times)

0 Members and 1 Guest are viewing this topic.

drec

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    hi the following counts all the files in a given folder and passes the value to a log file

    echo off
    SET Count=0
    FOR %%A IN (dir\*.*) DO SET /A Count += 1
    echo on
    ECHO.%Count%>>  %srclog%

    but what i want to do is do the same but with files up to 30 days old can you help tried the following and getting wierd results -

    SET cnt=0
    for /f %%A in ('dir /a-d-s-h /b ^| find /v /c /d +30 ""') do set /A cnt=%%A
    echo.%cnt%>>  %srclog%

    SET cnt2=0
    for %%A in (find . -type f -mtime +30 dir "dir\") do set /A cnt2 += 1
    echo.%cnt2%>>  %srclog%
    SET cnt2=0

    SET cnt3=0
    for %%A in (forfiles /P "dir" /D +30) do set /A cnt3 += 1
    echo.%cnt3%>>  %srclog%
    SET cnt3=0


    thanks in advance

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Pipe the output of robocopy through find, with the /L switch to only list what would be copied.

    Robocopy can filter by days.  Don't change anything - just run it in the folder you need to count.

    Code: [Select]
    robocopy . c:\magic /maxage:30 /fp /ndl /njh /njs /xx /L |find /c ":">>  %srclog%
    This portion of yours looks like a Linux command using the find on there, and not Windows.
    Code: [Select]
    (find . -type f -mtime +30 dir "dir\")
    « Last Edit: March 30, 2016, 03:53:30 AM by foxidrive »