[转]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& ...
随机推荐
- python 实现判断一个用户输入字符串是否是小数的小程序
要判断一个字符串是否是小数:1先判断小数点的个数,即如果是小数,则必须有且仅有一个'.'号2再分别判断'.'号的左右两边是否是数字: 判断左边时,如果负数,则左边包含'-'号:必须以'-'号开头(校验 ...
- IIS7 上传时出现'ASP 0104 : 80004005'错误
这个错误本身说的是上传的文件的大小超过IIS所设置的默认值,一般为200KB,压缩文件是个下下之选,我还真这么干过.后来了解到通过更改IIS对上传文件的默认大小设置,来实现上传. 下面说一下具体步骤: ...
- C#使用Linq对DataGridView进行模糊查找
针对DataGridView中已进行过数据绑定,即已向DataGridView中添加了一些数据,可以结合Linq查询,并让匹配查询的行高亮显示,如下图: 具体实现如下: [csharp] ...
- 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】
为什么要使用Lua进行游戏开发?转载请注明出处http://www.cnblogs.com/zisou/p/cocos2dx-lua1.html 上面一个问题我觉得在我们使用Lua之前需要深入思考的, ...
- web请求的状态码
摘录于 https://www.cnblogs.com/lovychen/p/6256343.html 1xx消息 这一类型的状态码,代表请求已被接受,需要继续处理.这类响应是临时响应,只包含状态行 ...
- Mac OS 10.12 - 安装Homebrew,像Ubuntu里面的apt一样简单地安装和删除软件!
Homebrew — macOS 不可或缺的套件管理器,Homebrew官方网站如此介绍自己!!! 中文官网:https://brew.sh/index_zh-cn.html 一,安装 打开shell ...
- hello lua
http://manual.luaer.cn/ http://www.lua.org/pil/contents.html #include <cstdio> #include <st ...
- 2018 Multi-University Training Contest 3
claris出题,orzzzzzz.前一天晚上说是贪心专场,喵喵喵??? 之前clsris说难题扔多校了,据说07,13是女生赛撤下来的题,喵喵喵??? A.Ascending Rating 题目传送 ...
- Mybatis的cache
相关类:org.apache.ibatis.executor.CachingExecutor 相关代码: public <E> List<E> query(MappedStat ...
- webpack快速入门——CSS分离与图片路径处理
1.在终端安装extract-text-webpack-plugin 2.引入插件 const extractTextPlugin = require("extract-text-webpa ...