[转]COPY OR MOVE FILES AND FOLDERS USING OLE AUTOMATION
本文转自:http://sqlindia.com/copy-move-files-folders-using-ole-automation-sql-server/
- I love playing around with automation stuff. In a recent automation task, I was to copy or move files and/or folders from one location to another in SQL Server without using SQLCMD.
- If you are novice to OLE automation in SQL server then I would recommend you to read my previous articles on OLE automation first.
- --The below configuration must be enabled
- /*
- sp_configure 'show advanced options', 1;
- GO
- RECONFIGURE with override;
- GO
- sp_configure 'Ole Automation Procedures', 1;
- GO
- RECONFIGURE with override;
- GO
- */
- DECLARE @source varchar(100) = 'E:\others\Lab_SQLIndia\src\TextFile.txt'
- , @destination varchar(100) = 'E:\others\Lab_SQLIndia\dest'
- , @operation tinyint = 1 -- 1=CopyFile, 2=CopyFolder, 3=MoveFile, 4=MoveFolder,
- DECLARE @fso int
- , @init int
- , @errFso int
- , @return varchar(100)
- SET @destination = @destination + '\'
- EXEC @init = sp_OACreate 'Scripting.FileSystemObject', @fso OUTPUT
- IF @init = 0 SELECT @errFso = @fso
- IF @init = 0 AND @operation = 1
- BEGIN
- IF @init = 0 SELECT @errFso = @fso
- EXEC @init = sp_OAMethod @fso,
- 'CopyFile',
NULL,- @source,
- @destination
- SET @return = 'FILE SUCCESSFULLY COPIED'
- END
- ELSE IF @init = 0 AND @operation = 2
- BEGIN
- IF @init = 0 SELECT @errFso = @fso
- EXEC @init = sp_OAMethod @fso,
- 'CopyFolder',
- NULL,
- @source,
- @destination
- SET @return = 'FOLDER SUCCESSFULLY COPIED'
- END
- ELSE IF @init = 0 AND @operation = 3
- BEGIN
- IF @init = 0 SELECT @errFso = @fso
- EXEC @init = sp_OAMethod @fso,
- 'MoveFile',
- NULL,
- @source,
- @destination
- SET @return = 'FILE SUCCESSFULLY MOVED'
- END
- ELSE IF @init = 0 AND @operation = 4
- BEGIN
- IF @init = 0 SELECT @errFso = @fso
- EXEC @init = sp_OAMethod @fso,
- 'MoveFolder',
- NULL,
- @source,
- @destination
- SET @return = 'FOLDER SUCCESSFULLY MOVED'
- END
- IF @init <> 0
- BEGIN
- DECLARE
- @Description varchar (255),
- @src varchar (255),
- @Helpfile varchar (255),
- @HelpID int
- EXECUTE sp_OAGetErrorInfo @errFso,
- @src OUTPUT,
- @Description OUTPUT,
- @Helpfile OUTPUT,
- @HelpID OUTPUT
- PRINT COALESCE(@src + @Description + @Helpfile + CAST(@HelpID as varchar(20)), 'Error Occurred')
- END
- ELSE
- PRINT @return
- EXEC sp_OADestroy @fso
[转]COPY OR MOVE FILES AND FOLDERS USING OLE AUTOMATION的更多相关文章
- Track files and folders manipulation in Windows
The scenario is about Business Secret and our client do worry about data leakage. They want to know ...
- Mac OS finder : 显示和隐藏文件[夹] show and hide files or folders
Finder默认是不显示隐藏文件[夹]的,要显示出怎么办? 要显示的话,可以GUI(graphic user interface)和CLI(command line interface)两种方式 CL ...
- depth: working copy\infinity\immediates\files\empty
depth: working copy\infinity\immediates\files\empty 有时间,需要整理下,svn 合并深度这四项:具体的意思.
- [Bash] Move and Copy Files and Folders with Bash
In this lesson we’ll learn how to move and rename files (mv) and copy (cp) them. Move index.html to ...
- Linux / mysql: is it safe to copy mysql db files with cp command from one db to another?
Copying is very simple for MyISAM and completely 100% risky (near suicidal) with InnoDB. From your q ...
- How to copy remote computer files quickly to local computer
if we want copy file from VM(Remote VM) to local computer. Always can not easy copy file so easy. no ...
- [Bash] Find Files and Folders with `find` in Bash
find is a powerful tool that can not only find files but it can run a command on each matching file ...
- [Bash] View Files and Folders in Bash
Sometimes when working at the command line, it can be handy to view a file’s contents right in the t ...
- C# copy source directory files with original folder to the destination path
private static void PathCopyFilesWithOriginalFolder() { ; try { string sourceDir = @"E:\Source& ...
随机推荐
- ABP框架中微服务跨域调用其它服务接口
AjaxResponse为ABP自动包装的JSON格式 /// <summary> /// 通过地址和参数取得返回OutPut数据 /// </summary> /// < ...
- WPF窗口启动时最大化
在xaml对应的后台代码文件的初始化方法中: public ShellView() { InitializeComponent(); #region 启动时串口最大化显示 Rect rc = Syst ...
- Day 7 深copy和浅Copy
dict.fromkeys的用法 1 2 3 4 5 6 7 8 9 10 11 #dict.fromkeys的用法 #例子1 dic = dict.fromkeys([1,2,3],[]) prin ...
- python web开发c6——阿里云上ubuntu+flask+gunicorn+nginx服务器部署(一)简单测试
简述 Nginx在服务器部署中的作用 请求通过Nginx实现反向代理,将请求提交给代理服务器.本文中只用了一台服务器,所以是代理到本机. gunicorn的作用 作为服务器代码的容器.接收Nginx的 ...
- C# __arglist 关键字
using System.Runtime.InteropServices; namespace Alpha { class Beta { [DllImport("msvcrt.dll&quo ...
- 组件基础—Vue学习笔记
ammm学习Vue有好几天了,今天遇到难点所以打算写一点随笔加深印象. 一.首先最简单的创建组件 1全局组件 Vue.component() Vue.component('hello',{ tem ...
- 【bzoj4503】 两个串 FFT
$FFT$套路题(然而我看错题了) 我们考虑化一下式子. 设当前比较的两个部分为$S[i....i+|T|-1]$和$T[0....|T|-1]$. 我们对串$T$中出现问号的位置全部赋值为$0$. ...
- 剑指offer五十三之表示数值的字符串
一.题目 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3.1 ...
- python3 判断大小端的一种方法
这里用到了array.array('H', [1])来测试大小端,[1]可以转化为十六进制的0x0001,占两位,00位高位, 01位低位,通过第一位就可以判断大小端. 如果是小端,则转化为bytes ...
- 【Java并发编程】:volatile变量修饰符
volatile用处说明 在JDK1.2之前,java的内存模型实现总是从主存(即共享内存)读取变量,是不需要进行特别的注意的.而随着JVM的成熟和优化,现在在多线程环境下volatile关键 ...