Computer Hope

Microsoft => Microsoft DOS => Topic started by: drec on March 29, 2016, 08:10:50 AM

Title: Hi all - trying to count files in a folder and pass it to a var can you help
Post by: drec on March 29, 2016, 08:10:50 AM
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
Title: Re: Hi all - trying to count files in a folder and pass it to a var can you help
Post by: foxidrive on March 30, 2016, 03:33:29 AM
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\")