调用FileSystemObject.CopyFile发生没有权限的错误
作者:朱金灿
来源:http://blog.csdn.net/clever101
最近编写一个JScript,在调用FileSystemObject.CopyFile发生没有权限的错误,具体如下图:
开始觉得这个错误挺诡异的,因为我是以管理员身份运行这个js的,怎么会没有权限呢?上网搜索了很多信息也没有找到答案。最后查了下MSDN,发现被错误信息误导了。MSDN是这样说的:
CopyFile Method
See Also
Copy Method| CopyFolderMethod | CreateTextFileMethod | DeleteFileMethod | MoveFileMethod
Applies To: FileSystemObjectObject
Language
- JScript
- VBScript
- Show All
Copies one or more files from one location to another.
object.CopyFile ( source, destination[, overwrite] )
Arguments
object
Required. The objectis always the name of a FileSystemObject.
source
Required.Character string file specification, which can include wildcard characters, forone or more files to be copied.
destination
Required.Character string destination where the file or files from source are tobe copied. Wildcard characters are not allowed.
overwrite
Optional.Boolean value that indicates if existing files are to be overwritten. If true,files are overwritten; if false, they are not. The default is true.Note that CopyFile will fail if destination has the read-onlyattribute set, regardless of the value of overwrite.
Remarks
Wildcard characters can only be used in the last pathcomponent of the source argument. For example, you can use:
[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")
[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"
But you cannot use:
[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\*\\R1???97.xls", "c:\\tempfolder")
[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder"
If source contains wildcard characters or destinationends with a path separator (\), it is assumed that destination is anexisting folder in which to copy matching files. Otherwise, destinationis assumed to be the name of a file to create. In either case, three things canhappen when an individual file is copied.
- If destination does not exist, source gets copied. This is the usual case.
- If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file.
- If destination is a directory, an error occurs.
An error also occurs if a source using wildcardcharacters doesn't match any files. The CopyFile method stops on thefirst error it encounters. No attempt is made to roll back or undo any changesmade before an error occurs.
通过阅读上面的接口说明,我发现我对FileSystemObject.CopyFile的接口的理解的。我以为可以这样用:比如我想把C:\\src\\1.cpp拷贝到D:\\MyProject,代码是这样写:
FileSystemObject.CopyFile("C:\\src\\1.cpp","D:\\MyProject");
实际上这是错误的,只能写成这样:
FileSystemObject.CopyFile("C:\\src\\1.cpp","D:\\MyProject\\1.cpp");
如果你想把src目录下所有cpp文件拷贝到D:\\MyProject目录下,可以这样写:
FileSystemObject.CopyFile("C:\\src\\*.cpp","D:\\MyProject");
看来以后遇到这样的问题第一步应该先查MSDN,不过微软的“没有权限”的错误提示也太坑爹了!
参考文献:
调用FileSystemObject.CopyFile发生没有权限的错误的更多相关文章
- SQL2008、SQL2013 执行Transact-SQL 语句或者批处理时发生了异常。错误5120
附加数据库的时候遇到问题,问题描述如下: 附加数据库 对于 服务器"服务器名"失败.(Microsoft.SqlServer.Smo) 执行Transact-SQL 语句或者批处理 ...
- C#解决微信支付Exception has been thrown by the target of an invocation(调用的目标发生了异常)的问题
今天搭建微信扫码支付环境的时候,一样的配置参数,调用连接提示错误 错误:调用的目标发生了异常 然后跟踪到执行 MD5 md5 = System.Security.Cryptography.MD5.Cr ...
- 【顽固BUG】Visual Studio 2013 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。
前言 突然怎么弄也无法断点调试了 输出如下: ------ Test started: Assembly: Server5.V2.dll ------ 调用的目标发生了异常. 而且网站运行提示: -- ...
- 【顽固BUG】Visual Studio 2015 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。
前言 突然怎么弄也无法断点调试了 输出如下: ------ Test started: Assembly: Server5.V2.dll ------ 调用的目标发生了异常. 而且网站运行提示: -- ...
- 系统禁用执行FIPS政策导致程序发生“调用的目标发生了异常”
工具是使用AES-256-CBC加密算法 问题 最近有客户反映, 在使用我们工具时候,会出现“调用的目标发生了异常”错误, 接到反馈之后, 我们进行了很多测试,甚至得到客户系统信息和framework ...
- IE下使用location对象有时会出现“没有权限”的错误
http://jadyyang.blog.sohu.com/145340845.html ——————————————————————————————————————————————————————— ...
- C#解决System.Security.Cryptography.MD5.Create()调用的目标发生了异常)的问题
今天搭建微信扫码支付环境的时候,一样的配置参数,调用连接提示错误 错误:调用的目标发生了异常 然后跟踪到执行 MD5 md5 = System.Security.Cryptography.MD5.Cr ...
- 未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。
未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息.数据类型不被支持. 博客分类: 雅芳生涯 .Net VB C# OracleMicrosoftSecurity ...
- jenkins用户权限配置错误,导致登录时提示:没有Overall/read权限
jenkins用户权限配置错误,导致登录时提示:没有Overall/read权限 由于初次接触jenkins,于是在搭建好jenkins以后,想要对用户进行管理,于是乎开始在系统管理->conf ...
随机推荐
- USB 3.0规范中译本 第10章 集线器,主机下行口以及设备上行口规范
本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 本章描述USB 3.0 集线器的体系结构要求.本章还描述主机下行口和集线器下行口之间功能性的不同之处,以及设 ...
- <Linux> Xen虚拟机下挂载
//创建源vdisk挂载目录: mkdir vd1 //创建目标vdisk挂载目录: mkdir vd2 //只需第一次执行: iscsiadm -m discovery --type sendta ...
- SDE 空间表操作
1. 创建空间表(包含st_geometry属性字段) CREATE TABLE sensitive_areas (area_id integer, name varchar(128), area_s ...
- asp.net中,<%#%>,<%=%>和<%%>各自是什么意思,有什么差别
在asp.net中经常出现包括这样的形式<%%>的html代码,总的来说包括以下这样几种格式: 一. <%%> 这样的格式实际上就是和asp的使用方法一样的,仅仅是asp中里面 ...
- CentOS 7安装fcitx中文输入法
安装过程例如以下: 1.增加EPEL源 EPEL7差点儿是CentOS必备的源: sudo yum install epel-release 2.加入mosquito-myrepo源 mosquito ...
- thinkphp中如何实现无限级分类?
thinkphp中如何实现无限级分类? 一.总结 1.数据表设计+递归算法 二.php实现无限级分类实例总结 1.数据库数据如下: 2.任务需求:给一个id,求自己和所有父亲. 3.实现代码如下:th ...
- 数据库基本查询语句(SQL常用增删改查语句 简单复习 mark)
SQL常用增删改查语句 1增 1.1[插入单行]insert [into] <表名> (列名) values (列值)例:insert into Strdents (姓名,性别,出生日期) ...
- React Native 开发环境安装和配置使用报错: -bash: react-native: command not found
[React Native 开发环境安装和配置:-bash: react-native: command not found 报错: 前提是安装homebrew,node.js ,npm ,watc ...
- html5中input的type类型有哪些(总结)
html5中input的type类型有哪些(总结) 一.总结 一句话总结:时间.颜色.(邮件.电话.url).(数字.数字范围).搜索search 二.html5中input的type类型 值 描述 ...
- 微信小程序要调数据 微信小程序 for 循环详解
现在要完成这样的效果: 我的代码是: <view class="l-setlist clr" > <template name="listab" ...