Solved need a batch file to see previous days files

August 17, 2020 at 18:14:12
Specs: Windows 10
This batch file I found is beautiful

@echo off
set yyyy=
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
set %%x=%%u
set %%y=%%v
set %%z=%%w
set $d1=
set $tok=))
if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100
set CurDate=%mm%/%dd%/%yyyy%
set dayCnt=%1
if "%dayCnt%"=="" set dayCnt=1
REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100
:CHKDAY
if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1
:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through
:SET31
set /A dd=31 + %dd%
goto CHKDAY
:SET30
set /A dd=30 + %dd%
goto CHKDAY
:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29
:SET28
set /A dd=28 + %dd%
goto CHKDAY
:SET29
set /A dd=29 + %dd%
goto CHKDAY
:DONE
if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%
echo Date %dayCnt% day(s) before %CurDate% is %mm%/%dd%/%yyyy%
dir|find "%mm%/%dd%/%yyyy%"


See More: need a batch file to see previous days files


#1
August 17, 2020 at 18:18:45
Batch file does a DIR with date as far back as 100 days(I think) - only last line in batch file is mine.
To use, enter filename a space followed by # of days back from current date you wanrt a DIR.

For example, this_batchfile_name 4
will do a dir for four days ago.


Reply ↓  Report •

#2
August 17, 2020 at 20:10:28
✔ Best Answer
Refer to this PowerShell find files modified in last 24 hours and PowerShell get last modified time of files in folder

We can modifie it as below : back as 100 days

So, you can get all previous 100 days files in one line with powershell :

Get-Item -Path "$home\Desktop\*.*" | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-100) } | Foreach { $_.FullName }

And you can use this command in powershell with a batch file easily :
Just change the variable Folder as your needs :

@echo off
Title See previous days files
:Main
cls
Set "Folder=%userprofile%\Desktop"
echo( Type the number of days :
Set /P "PreviousDays="

Powershell ^
Get-Item -Path "%Folder%\*.*" ^
| ? { $_.LastWriteTime -gt (Get-Date^).AddDays(-%PreviousDays%^) } ^
| %% { $_.FullName }
pause
Goto Main

message edited by Hackoo


Reply ↓  Report •
Related Solutions


Ask Question