none
How to Check files which is older than 14 days in particuler folder using IF condition in Batch script RRS feed

  • Question

  • Hi,

    I have to check the zip files created before 14 days by using Batch script.

    Any conditional statement needed ?

    Thanks,

    Jitu

    Monday, February 10, 2014 10:06 AM

Answers

  • Hi,

    I have to check the zip files created before 14 days by using Batch script.

    Any conditional statement needed ?

    Yes, of course you need some conditional statement! The following line will tell you which .txt files in the folder d:\temp are older than 14 days: 

    forfiles.exe /d -14 /M *.txt /p d:\temp /c "cmd /c @echo @file"

    Monday, February 10, 2014 11:58 AM

All replies

  • Hi,

    I have to check the zip files created before 14 days by using Batch script.

    Any conditional statement needed ?

    Yes, of course you need some conditional statement! The following line will tell you which .txt files in the folder d:\temp are older than 14 days: 

    forfiles.exe /d -14 /M *.txt /p d:\temp /c "cmd /c @echo @file"

    Monday, February 10, 2014 11:58 AM
  • Hi ,

    Is There any Else Condition for this statement, So that I can Exit without doing the tasks.

    I mean to say.

    IF
    Do this..
    Else
    Exit..

    Thanks in Advance,

    Jitu

    Tuesday, February 11, 2014 2:21 AM
  • Hi ,

    Is There any Else Condition for this statement, So that I can Exit without doing the tasks.

    I mean to say.

    IF
    Do this..
    Else
    Exit..

    Thanks in Advance,

    Jitu

    You need to explain in more detail what you are trying to achieve.
    Tuesday, February 11, 2014 6:54 AM
  • Hi,

    I am using this below script to delete 14 days old zip files.

    @echo off
    SET Days=14
    FORFILES /S /M *.zip* /D -%Days% /C "CMD /C DEL @file" 2>Nul

    But this script is failing if the files are not present in the same folder.

    So I am thinking to loop the statement to check if files are not there exit from the loop

    Thanks,

    Jitu

    Wednesday, February 12, 2014 3:18 AM
  • But this script is failing if the files are not present in the same folder.

    So I am thinking to loop the statement to check if files are not there exit from the loop.

    The script does not fail - it reports that no files are found. You can detect this like so:

    if %ErrorLevel% NEQ 0 echo "There are no zip files!"

    There is no loop in your script that you can exit from.

    Wednesday, February 12, 2014 6:43 AM