title: how to create batch file to copy files to a shared folder with full access then logs all result & errors to a file?
body: <p>I have created the below batch file but no success.</p>
  
  <pre><code>@ECHO OFF
  
  @ECHO "Backup process started."
  
  @SET TARGET_FILES = "\\pc1\temp\*.mdb"
  @ECHO "TARGET_FILES:%TARGET_FILES%"
  
  @SET DESTINATION_FOLDER = "\\pc1\temp\Backups"
  @ECHO "DESTINATION_FOLDER:%DESTINATION_FOLDER%"
  
  @SET BACKUP_FOLDER = "Backup%date:~10,4%%date:~4,2%%date:~7,2%"
  @ECHO "BACKUP_FOLDER:%BACKUP_FOLDER%"
  
  @SET FINAL_FOLDER = "%DESTINATION_FOLDER%\%BACKUP_FOLDER%"
  MKDIR %FINAL_FOLDER%
  @ECHO "DIRECTORY CREATED:%FINAL_FOLDER%"
  
  XCOPY %TARGET_FILES% %FINAL_FOLDER% &gt;&gt; %FINAL_FOLDER%\%BACKUP_FOLDER%.log
  
  @ECHO "Backup process ended successfully."
  
  @ECHO ON
  </code></pre>
  
  <p>Environment:
  It will be scheduled task in C:\Windows\Tasks using Windows XP SP3</p>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>"Backup process started."
  "TARGET_FILES:"
  "DESTINATION_FOLDER:"
  "BACKUP_FOLDER:"
  The syntax of the command is incorrect.
  "DIRECTORY CREATED:"
  Invalid number of parameters
  "Backup process ended successfully."
  </code></pre>
  
  <p>Any guidance on the right direction is appreciated.</p>
  
  <p><strong>UPDATES1:</strong>
  I've noticed that my variables were not set.</p>
  
  <p><strong>UPDATES2:</strong></p>
  
  <pre><code>@ECHO OFF
  ECHO Backup process started.
  
  set TARGET_FILES=\\pc1\temp\*.mdb
  ECHO TARGET_FILES "%TARGET_FILES%"
  
  SET DESTINATION_FOLDER=\\pc1\temp\Backups
  ECHO DESTINATION_FOLDER "%DESTINATION_FOLDER%"
  
  SET BACKUP_FOLDER=Backup%date:~0,4%%date:~5,2%%date:~8,2%
  ECHO BACKUP_FOLDER "%BACKUP_FOLDER%"
  
  SET FINAL_FOLDER=%DESTINATION_FOLDER%\%BACKUP_FOLDER%
  MKDIR "%FINAL_FOLDER%"
  ECHO DIRECTORY CREATED "%FINAL_FOLDER%"
  
  XCOPY "%TARGET_FILES%" "%FINAL_FOLDER%" &gt;&gt; "%FINAL_FOLDER%\%BACKUP_FOLDER%.log"
  
  ECHO Backup process ended successfully.
  
  @ECHO ON
  </code></pre>
  
  <p><strong>OUTPUT FOR UPDATES2:</strong></p>
  
  <pre><code>Backup process started.
  TARGET_FILES "\\pc1\temp\*.mdb"
  DESTINATION_FOLDER "\\pc1\temp\Backups"
  BACKUP_FOLDER "Backup20120214"
  DIRECTORY CREATED "\\pc1\temp\Backups\Backup20120214"
  Backup process ended successfully.
  </code></pre>
  
  <p><strong>LOG</strong></p>
  
  <pre><code>\\pc1\temp\file1.mdb
  \\pc1\temp\file1_be.mdb
  2 File(s) copied
  </code></pre>
  
  <p>With the new code (UPDATES2), I have successfully copied all mdb files to target folder <strong>but all my echo messages were not logged. How can I include all my echo messages to be logged?</strong></p>