Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
fudeboy

Listing all files from a date interval “Batch file”

Recommended Posts

I need to do a batch file wich order all files by a date interval, example:

 

@echo off echo Input the date(dd/mm/yyyy):
set /p compDate=

 

::After that i will compare from the actual day (%date%), example:

set interval = %compDate% - %date%... Something like that

::After that i need to list all files from a specific directory, example:

 

echo Input the directory:
set /p directory=
SET Exit= %UserProfile%\Desktop\test.txt

 

::After that i might i need the dir /tc to get the creation date, example:

 

pushd "%directory%"

dir /s /tc /a-d > %Exit%

 

::After that, i dont know how to get only the lines wich the date interval are, example:

 

Today is 19/08/2014, but i want to search all files created from day 10/07/2014. So i have to copy all lines which have the date 10/07/2014, 11/07/2014, 12/07/2014 and so on until stop on today created files.

I tried with findstr but i can't set the date interval, just a specific date to search in the .txt created.

Somebody know how to do that ?

Edited by fudeboy

Share this post


Link to post
Share on other sites

Well, if you use "ISO" date format it might be easier.

 

Something *like* this:

@ECHO OFFSETLOCAL ENABLEEXTENSIONSFOR /F "tokens=1,2,3,* delims=/ " %%A IN ('DIR /tc /OD C:\batches\') DO (IF %%B leq 12 IF %%C%%B%%A lss 20110322 ECHO %%A/%%B/%%C %%D)

In the above I am using my local settings, where dates are "dd/mm/yyyy" you will need to change order of variables and/or separators to suit your local settings.

 

jaclaz

Share this post


Link to post
Share on other sites

Sometimes it's more fun to use powershell!

 

InBTween.ps1

$ScriptPath = Split-Path $MyInvocation.MyCommand.Path$ScriptName = $MyInvocation.MyCommand.NamePush-Location $ScriptPath$ToDate = [DateTime]::TodayWrite-Host 'Today is' $ToDate.ToShortDateString()$FromDate = Read-Host 'Enter a Search From Date'If (($FromDate -as [DateTime]) -ne $null) {    $FromDate = [DateTime]::Parse($FromDate)    GCI . -exclude $ScriptName -rec | Sort CreationTime | Where {        $_.CreationTime -ge $FromDate -and $_.CreationTime -le $ToDate    } | % {$_.CreationTime.ToShortDateString() + "`t" + $_.FullName    } | Tee results.txt} Else {    'You did not enter a valid date!'}Write-Host "Press any key to exit . . . " -ForegroundColor Yellow$X = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")Pop-Location

This script is designed to search from the root of its own directory tree and the output will be written to a new file in that directory named results.txt.

 

If the script doesn't run, you may need to type the following into a powershell window first:

Set-ExecutionPolicy RemoteSigned

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...