作者:朱金灿

来源: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,不过微软的“没有权限”的错误提示也太坑爹了!

参考文献:

1.  javascript 操作文件实现方法小结

调用FileSystemObject.CopyFile发生没有权限的错误的更多相关文章

  1. SQL2008、SQL2013 执行Transact-SQL 语句或者批处理时发生了异常。错误5120

    附加数据库的时候遇到问题,问题描述如下: 附加数据库 对于 服务器"服务器名"失败.(Microsoft.SqlServer.Smo) 执行Transact-SQL 语句或者批处理 ...

  2. C#解决微信支付Exception has been thrown by the target of an invocation(调用的目标发生了异常)的问题

    今天搭建微信扫码支付环境的时候,一样的配置参数,调用连接提示错误 错误:调用的目标发生了异常 然后跟踪到执行 MD5 md5 = System.Security.Cryptography.MD5.Cr ...

  3. 【顽固BUG】Visual Studio 2013 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。

    前言 突然怎么弄也无法断点调试了 输出如下: ------ Test started: Assembly: Server5.V2.dll ------ 调用的目标发生了异常. 而且网站运行提示: -- ...

  4. 【顽固BUG】Visual Studio 2015 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。

    前言 突然怎么弄也无法断点调试了 输出如下: ------ Test started: Assembly: Server5.V2.dll ------ 调用的目标发生了异常. 而且网站运行提示: -- ...

  5. 系统禁用执行FIPS政策导致程序发生“调用的目标发生了异常”

    工具是使用AES-256-CBC加密算法 问题 最近有客户反映, 在使用我们工具时候,会出现“调用的目标发生了异常”错误, 接到反馈之后, 我们进行了很多测试,甚至得到客户系统信息和framework ...

  6. IE下使用location对象有时会出现“没有权限”的错误

    http://jadyyang.blog.sohu.com/145340845.html ——————————————————————————————————————————————————————— ...

  7. C#解决System.Security.Cryptography.MD5.Create()调用的目标发生了异常)的问题

    今天搭建微信扫码支付环境的时候,一样的配置参数,调用连接提示错误 错误:调用的目标发生了异常 然后跟踪到执行 MD5 md5 = System.Security.Cryptography.MD5.Cr ...

  8. 未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。

    未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息.数据类型不被支持. 博客分类: 雅芳生涯 .Net VB C# OracleMicrosoftSecurity  ...

  9. jenkins用户权限配置错误,导致登录时提示:没有Overall/read权限

    jenkins用户权限配置错误,导致登录时提示:没有Overall/read权限 由于初次接触jenkins,于是在搭建好jenkins以后,想要对用户进行管理,于是乎开始在系统管理->conf ...

随机推荐

  1. [AngularJS Ng-redux] Integrate ngRedux

    Up to this point, we have created an effective, yet rudimentary, implementation of Redux by manually ...

  2. Longest Increasing Subsequences(最长递增子序列)的两种DP实现

    一.本文内容 最长递增子序列的两种动态规划算法实现,O(n^2)及O(nlogn).     二.问题描述 最长递增子序列:给定一个序列,从该序列找出最长的 升序/递增 子序列. 特点:1.子序列不要 ...

  3. GridView在PopWindow中OnItemClick不响应

    在安卓4.0系统中,GridView在PopWindow中OnItemClick不响应,但是有按压效果.需要PopWindow的Show时加入这行代码: popupWindow.setFocusabl ...

  4. 细说HTML头部标签

    原文 简书原文:https://www.jianshu.com/p/4270b1d1037d 大纲 1.头部标签列表 2.头部标签详解 1.头部标签列表 <!DOCTYPE html> & ...

  5. opencv和linux的关联

    这是一篇关于opencv和linux关联的文章

  6. Java编程思想第四版 *第五章 个人练习

    练习3:(1)创建一个带默认构造器(即无參构造器)的类.在构造器中打印一条消息.为这个类创建一个对象.P116 public class Test{ public Test(){ System.out ...

  7. Android Notification如何显示表情?

    遇到这种分析用什么实现的,肯定要祭出大杀器Android Device Monitor(AS在Tools->Android)打开之后,选中连接的设备,然后点击小手机图标,即可导出UI层次图.咱们 ...

  8. C++ 如何快速清空vector以及释放vector内存?

    平时我们在写代码时候,有思考过要主动去释放vector的内存吗? 1.对于数据量不大的vector,没有必要自己主动释放vector,一切都交给操作系统. 2.但是对于大量数据的vector,在vec ...

  9. 常用JS验证函数总结

    JS验证Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/- ...

  10. erlang中如何调试程序

    学习一门语言,当学习那些基本语法的时候,我们常常会忽略它的程序调试,当程序稍微复杂一点的时候,我们不能保证程序的完全正确,我们会为其发愁,这时,程序的调试就变得相当重要了.    在erlang环境搭 ...