title: Batch script to delete files older than 20 minutes
body: <p>Hi Iam new to batch scripting I want to create batch script which deletes the files older than 20 minutes.</p>
  
  <p>I have searched the internet and found one batch script:</p>
  
  <pre class="lang-bat prettyprint-override"><code>@echo off
  :: Wmic removes regional differences - it has problems with commas in filenames.
  setlocal
  
  for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
  set "YY=%dt:~2,2%" &amp; set "YYYY=%dt:~0,4%" &amp; set "MM=%dt:~4,2%" &amp; set "DD=%dt:~6,2%"
  set "HH=%dt:~8,2%" &amp; set "Min=%dt:~10,2%" &amp; set "Sec=%dt:~12,2%"
  
  set "stamp=%YYYY% %MM% %DD% %HH% %Min%"
  
  call :DateToMinutes %stamp% NowMins
  
  for /f "delims=" %%a in ('dir * /a-d /b') do call :CheckMins "%%~fa"
  pause
  goto :EOF
  
  :CheckMins
  set "filestamp="
  set "filemins="
  set "MinsOld="
  set "YY=" &amp; set "YYYY=" &amp; set "MM=" &amp; set "DD="
  set "HH=" &amp; set "Min=" &amp; set "Sec=" &amp; set "dt="
  set "file=%~1"
  set "filea=%file:\=\\%"
  WMIC DATAFILE WHERE name="%filea%" get lastmodified | find "." &gt;file.tmp
  for /f %%a in (file.tmp) do set "dt=%%a"
  set "YY=%dt:~2,2%" &amp; set "YYYY=%dt:~0,4%" &amp; set "MM=%dt:~4,2%" &amp; set "DD=%dt:~6,2%"
  set "HH=%dt:~8,2%" &amp; set "Min=%dt:~10,2%" &amp; set "Sec=%dt:~12,2%"
  set "filestamp=%YYYY% %MM% %DD% %HH% %Min%"
  del file.tmp 2&gt;nul
  
  if not defined yyyy goto :EOF
  
  call :DateToMinutes %filestamp% FileMins
  
  set /a MinsOld=%NowMins%-%FileMins%
  :: echo Now:%NowMins% File:%FileMins% Fileage:%minsold% "%~1"
  if %MinsOld% gtr 20 del "%file%"
  goto :EOF
  
  :DateToMinutes
  setlocal
  set yy=%1&amp;set mm=%2&amp;set dd=%3&amp;set hh=%4&amp;set nn=%5
  if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
  set /a dd=100%dd%%%100,mm=100%mm%%%100
  set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
  set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
  if 1%hh% LSS 20 set hh=0%hh%
  if /i {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&amp;set/a hh-=88
  if /i {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
  if /i {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
  set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
  endlocal&amp;set %6=%j%&amp;goto :EOF
  </code></pre>
  
  <p>But it deletes the files from current directory. But my scenario is to delete the files from specific location.</p>