#---------------------------------------------------------------------------------------------#
#--Script to copy files from one location to another with a cool Progressbar --#
# If you want to test it - Change the source path and target path with a relevant directory 
# in your computer - 
# $SOURCE_PATH
# $TARGET_PATH
#---------------------------------------------------------------------------------------------#
# Note : The script will copy only files from source to target, please use it carefully
# if the low disk space problem in target drive. 
# Do not use C:\ drive or drive where Operating system in installed.
#---------------------------------------------------------------------------------------------#

function Copy-Files([string]$SOURCE_PATH, [string]$TARGET_PATH)
{
  
  $FILES_COLLECTION=ls $SOURCE_PATH | where { $_.Mode -notcontains "d----" } | foreach { $_.FullName}$FILES_COUNT=$FILES_COLLECTION.count
  
  for ( $t =0; $t -lt $FILES_COUNT ; $t++) 
  {
    $status = [int] (($t/$FILES_COUNT) * 100) 
    
    #--Get the full-file name and only leaf name of the file --# 
    $THIS_FILE_FULL_NAME = $FILES_COLLECTION[$t] $THIS_FILE_NAME = Split-Path $THIS_FILE_FULL_NAME -leaf
  
    #--Set the target location --3 
    $THIS_FILE_TARGET = "${TARGET_PATH}\${THIS_FILE_NAME}"
  
    #--write progress with progressbar --# 
    Write-Progress -id 1 -Activity "File-Copy Status - [$status]" -Status "Copying to $THIS_FILE_NAME to $TARGET_PATH " -PercentComplete $status
  
    #--Copy Step --# 
    Copy-Item $THIS_FILE_FULL_NAME $THIS_FILE_TARGET

  
  }
}

#---------------------------------------------------------------------------------------------#
Copy-Files "D:\Dir1" "D:\Dir2"


#---------------------------------------------------------------------------------------------#
# End of Code
#---------------------------------------------------------------------------------------------#