title: Batch script to copy a file from one network share to another based on lastmodified or creation date
body: <p>I have two network shared drives: lets call them: <strong>DriveA</strong> and <strong>DriveB</strong>.</p>
  
  <p>There are two files which get generated at <strong>DriveA</strong> on a daily basis, and I want to copy the latest files to <strong>DriveB/Folder1/fileA</strong> and <strong>DriveB/Folder2/fileB</strong> everyday.</p>
  
  <p>Can anyone please provide me solution wherein I can copy the files based on creation date:</p>
  
  <ol>
  <li>Copy fileA(<em>creation date: 17July</em>) to <strong>DriveB/Folder1</strong></li>
  <li>Copy fileB(<em>creation date: 17July</em>) to <strong>DriveB/Folder2</strong></li>
  </ol>
  
  <p>I did come up with a solution but, it copies the file based on "today's date".</p>
  
  <p><code>SET usernameID=useremail@domain.com
  SET usernameDOMAIN=11111111
  SET password=pwd@1234
  net use "\\111.444.222.777\FOLDER" /USER:%usernameID% %password% /persistent:no
  set source=\\222.111.333.444\FOLDER\FOLDER2\Report_
  net use "\\DOMAIN\storage\2012-0151_hms_ux\Hadoop\LiveDataLandingZoneDWH" /user:usermail@domain.com pwd@1234 /persistent:no
  set dest=\\code1\storage\2012-0151_hms_ux\Hadoop\LiveDataLandingZoneDWH\Input\Report\Report_
  for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
  set today=%MyDate:~0,4%%MyDate:~4,2%%MyDate:~6,2%
  echo %today%
  :copy
  copy "%source%%today%0700.csv" "%dest%%today%0700.csv"
  IF ERRORLEVEL 0 goto disconnect
  goto end
  pause
  :disconnect 
  goto end
  pause
  :end
  pause</code></p>
  
  <p>EDIT 1:</p>
  
  <p>Now I'm using the below command to copy the files on the date 16/Jul/2017:
  <code>xcopy C:\Users\Desktop\report\ActualHRC_*.csv C:\Users\Downloads /D:07-16-2017
  pause</code></p>
  
  <p>How can I provide the <code>/D:m-d-y</code> dynamically? I mean, the variables should take the <code>m</code>, <code>d</code> and <code>y</code> from the system.</p>
  
  <p>Thanks in advance!</p>