daily pastebin goal
7%
SHARE
TWEET

Copy files with SQL

priore Apr 28th, 2012 198 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --
  2. --  Created by Danilo Priore.
  3. --  Copyright (c) 2012 Prioregroup.com. All rights reserved.
  4. --
  5. --  Permission is hereby granted, free of charge, to any person obtaining a copy
  6. --  of this software and associated documentation files (the "Software"), to deal
  7. --  in the Software without restriction, including without limitation the rights
  8. --  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. --  copies of the Software, and to permit persons to whom the Software is
  10. --  furnished to do so, subject to the following conditions:
  11. --
  12. --  The above copyright notice and this permission notice shall be included in
  13. --  all copies or substantial portions of the Software.
  14. --
  15. --  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. --  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. --  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. --  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. --  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. --  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. --  THE SOFTWARE.
  22. --
  23.  
  24. CREATE PROCEDURE spCopyFile(@source varchar(255), @dest varchar(255))
  25. AS
  26.  
  27. DECLARE @hr int
  28. DECLARE @ole_FileSystem int
  29. DECLARE @True int
  30. DECLARE @src varchar(250), @desc varchar(2000)
  31.  
  32. EXEC @hr = sp_OACreate 'Scripting.FileSystemObject', @ole_FileSystem OUT
  33. if @hr <> 0
  34. begin
  35.    exec sp_OAGetErrorInfo @ole_FileSystem, @src OUT, @desc OUT
  36.    raiserror('Object Creation Failed 0x%x, %s, %s',16,1,@hr,@src,@desc)
  37.    return
  38. end
  39.  
  40. EXEC @hr = sp_OAMethod @ole_FileSystem, 'CopyFile',null, @source, @dest
  41. if @hr <> 0
  42. begin
  43.    exec sp_OAGetErrorInfo @ole_FileSystem, @src OUT, @desc OUT
  44.    exec sp_OADestroy @ole_FileSystem
  45.    raiserror('Method Failed 0x%x, %s, %s',16,1,@hr,@src,@desc)
  46.    return
  47. end
  48.  
  49.  
  50. cleanup:
  51. exec @hr = sp_OADestroy @ole_FileSystem
  52. return
  53. GO
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top