logo
down
shadow

Compare current date with file modified date in batch file


Compare current date with file modified date in batch file

By : Mike Railey
Date : November 22 2020, 01:01 AM
wish help you to fix your issue Update
Since you have forfiles on your server, this is easy. To check for files older than 1 day old, just use forfiles /D -1. For files over 2 days old, /D -2.
code :
forfiles /D -2 /M *.log /P C:\Source /C "cmd /c move @file c:\Destination"
@echo off
setlocal enableextensions

set "source=c:\Source"
set "destination=c:\Destination"

:: store today's date in %today%
for /f "tokens=2" %%I in ('echo %date%') do set "today=%%I"

for %%I in ("%source%\*") do (
    rem :: scrape MM/DD/YYYY from %%~tI
    for /f %%a in ('echo %%~tI') do (

        rem :: compare the two dates
        if "%%a" neq "%today%" (
            echo %%~nxI: %%a does not equal %today%.  Moving.
            >NUL move /y "%%~fI" "%destination%"
        ) else (
            echo %%~nxI: %%a equals %today%.  Skipping.
        )
    )
)


Share : facebook icon twitter icon
Can a batch file change the system date; save file with attributes; change date back to current date?

Can a batch file change the system date; save file with attributes; change date back to current date?


By : user2283577
Date : March 29 2020, 07:55 AM
seems to work fine Yes, a batch file can do it, but I wouldn't recommend it. To set the date in Windows, you use the DATE command. To set the date to 01/01/2010, you would execute this command at the command prompt:
code :
date 01-01-2010
help date
help time
Comparing a modified file date with the current date in a batch file

Comparing a modified file date with the current date in a batch file


By : Amanda Everett
Date : March 29 2020, 07:55 AM
This might help you I like dbenham's way, but if you want to make your code work you can do like this:
code :
set currentDate=%date%
SET filename="C:\MyFile.txt"

FOR %%f IN (%filename%) DO SET filedatetime=%%~tf
IF %filedatetime:~0, 10% == %currentDate% goto same

goto notsame

:same
echo Dates the same, do some code here

goto next

:notsame
echo Dates NOT the same, do some code here
goto end

:next
Batch: ignore processing of file having current date as part of its name or file created on current date

Batch: ignore processing of file having current date as part of its name or file created on current date


By : MC Đạt
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have a requirement to search for files having date stamp on their name and zip them. The zipping part is working fine. But, I need to ignore the file which has current date stamp as part of its name. File name pattern is like below : , A little simplicication:
code :
for /f "tokens=2-4 delims=/ " %%a in ('date /T'
  ) do set year=%%c&set month=%%a&set day=%%b&set CurrentDate=%%c-%%a-%%b
echo %CurrentDate%
FOR %%c in (%1%filename*.*) DO (
 echo %%c
 REM code to ignore file with CurrentDate
 ECHO "%%c"|FINDSTR "%currentdate%" >nul
 IF ERRORLEVEL 1 (
 REM code to zip older file(s)
 )
)
for /f "tokens=2-4 delims=/ " %%a in ('date /T'
  ) do (
 set year=%%c
 set month=%%a
 set day=%%b
 set CurrentDate=%%c-%%a-%%b
 )
:: comment
if modified date is same as current date then it will copy one file to a location

if modified date is same as current date then it will copy one file to a location


By : Netix295
Date : March 29 2020, 07:55 AM
seems to work fine I'm writing a batch file that should do as follows: , The starting (has to be on the same line as the if:
code :
if %filedatetime:~0,10% == %currentDate% 
pause
(
ROBOCOPY C:\Users\ANI\Desktop\IMP  C:\downloads\%date:~-4,4%%date:~-10,2%%date:~-7,2%,RetailEmp.txt
pause
)
if %filedatetime:~0,10% == %currentDate% (
  pause
  ROBOCOPY C:\Users\ANI\Desktop\IMP  C:\downloads\%date:~-4,4%%date:~-10,2%%date:~-7,2%,RetailEmp.txt
  pause
)
Compare current time to file date time last modified in Windows Batch File

Compare current time to file date time last modified in Windows Batch File


By : y2a1nf3kted
Date : March 29 2020, 07:55 AM
I wish this helpful for you Another implementation using from your :
code :
@Echo Off
Set "filename=last_run.txt"
Set "minutes=15"
If Not Exist "%filename%" GoTo :PrintList
"%__APPDIR__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile If(((Get-Date)-(Get-Item ".\%filename%").LastWriteTime).Minutes -LT %minutes%){Exit 1}
If ErrorLevel 1 Exit /B
Rem Your payload below here.

:PrintList
CD.>"%filename%"
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org