title: Copy with percentage completion
body: <p>I'm currently trying to create a batch file, which actually copy a folder from a server to a clients machine. And I'm playing around with batch file, using xcopy, and it gives me the percentage of completion. I'm not a programmer, i just modified a tiny mount of lines from a code which i got from: <a href="https://answers.yahoo.com/question/index?qid=20120229012108AA8EwOA" rel="nofollow">https://answers.yahoo.com/question/index?qid=20120229012108AA8EwOA</a> (all credit goes to "Jake").</p>
  
  <p>However, the batch file will actually copied the whole files, including the parent folders, did i miss something here?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>@echo off&amp;color a
  setlocal enabledelayedexpansion
  
  cd /
  mkdir ZZZDestination
  set startdir="C:\ZZZSource\Depth1\Depth2\the files"
  set enddir="C:\ZZZDestination\"
  
  echo.
  echo Press any key to continue
  PAUSE&gt;nul
  
  for /f "tokens=1,2,3,4,5" %%a in ('dir /s %startdir%^|findstr bytes') do if /i not "%%e"=="free" set qtyfiles=%%a
  set filecount=0
  for /f "tokens=*" %%a in ('dir /a-d-h-s /s /b %startdir%') do (
  xcopy /z /q /s /e /y "%%a" "%enddir%\%%~pa\*.*" &gt;nul
  set /a filecount=!filecount!+1
  set /a percentage=!filecount!*100 / !qtyfiles!
  cls
  echo.
  echo Copying files, PLEASE DO NOT CLOSE THIS WINDOW
  echo ======================================================
  echo Please wait for copying:       !percentage!%% Completed
  echo ======================================================
  )
  echo.
  echo DONE, please press any key to exit..
  PAUSE&gt;nul
  </code></pre>
  
  <p>I have tried to modified the</p>
  
  <pre><code>xcopy /z /q /s /e /y "%%a" "%enddir%\%%~pa\*.*" &gt;nul
  </code></pre>
  
  <p>into</p>
  
  <pre><code>xcopy /z /q /s /e /y "%%a" "%enddir%" &gt;nul 
  </code></pre>
  
  <p>It works, and does not copy the parent folders (e.g. ZZZSource\Depth1\Depth2).
  However, the files inside the sub-folders under "C:\ZZZSource\Depth1\Depth2\the files" will be copied out from the folder.</p>
  
  <p>For example, under folder "C:\ZZZSource\Depth1\Depth2\the files", there are folders A B C, and inside those, there are each 4-5 files. Those 4-5 files, will all be copied out into "C:\ZZZDestination\" instead of under "C:\ZZZDestination\A\" for example.</p>
  
  <p>Anyone have any idea?</p>
  
  <p>Thank you in advance.</p>