how to copy directory using sql server

SET @Query = ‘xcopy “{Source  Directory Path}\*.*” “{Destination Directory Path}\” /e /i /h /y ‘
PRINT @Query
EXEC master.dbo.xp_cmdshell @Query


  1. “*.*” Copy all directory and file in source path.
  2. “/e” Copies directories and sub directories, including empty ones. Same as /S /E. May be used to modify /T.
  3. “/i” If destination does not exist and copying more than one file, assumes that destination must be a directory.
  4. “/h” Copies hidden and system files also.
  5. “/y” Overwrites existing files without prompting.

Leave a Reply

Protected with IP Blacklist CloudIP Blacklist Cloud