调用FileSystemObject.CopyFile发生没有权限的错误
来源:互联网 发布:淘宝竞品分析报告 编辑:程序博客网 时间:2024/06/18 11:23
作者:朱金灿
来源: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\\1.cpp");
如果你想把src目录下所有cpp文件拷贝到D:\\MyProject目录下,可以这样写:
FileSystemObject.CopyFile("C:\\src\\*.cpp","D:\\MyProject");
看来以后遇到这样的问题第一步应该先查MSDN,不过微软的“没有权限”的错误提示也太坑爹了!
参考文献:
1. javascript 操作文件实现方法小结
- 调用FileSystemObject.CopyFile发生没有权限的错误
- CopyFile 没有权限错误
- CopyFile没有执行
- Microsoft.XMLHTTP“没有权限”的错误
- Ajax : "没有权限" 错误
- 调用CopyFile()重命名文件
- WinXP的IIS中解决FileSystemObject不能写入已有文件或删除文件提示没有权限的问题时学到的两个知识点
- Automation错误 定义的应用程序或对象错误-"Scripting.FileSystemObject"
- 调用/"server.createObject(/"excel.application/")/"的时候发生的错误
- 消费者调用提供者发生错误
- 调用MSSQLSERVER的系统过程xp_cmdshell发生错误
- 对于调用DataAdapter.Update 方法时发生的错误解决办法
- C#调用Halcon进行OCR训练时发生的错误
- IE下的“SCRIPT70: 没有权限”的错误
- 远程调用 发生的
- Shiro无权限,不进行unauthorizedUr无权限l跳转,而是没有权限的错误
- 关闭窗口时防止出现“没有权限”的错误
- 如何解决AJAX中跨域访问出现'没有权限'的错误
- Linux grep命令用法
- 13年省赛总结
- 判断外部存储是SD卡还是u盘的方法
- UNIX环境高级编程读书笔记(九)—进程关系 (1)
- 一点一滴的培养你的领导气质
- 调用FileSystemObject.CopyFile发生没有权限的错误
- ExtJS表单之复选框CheckboxGroup展示与取值
- C++中的单例模式
- jquery map方法
- c++设计一个类,但是不能被继承
- 双绞线的标准接法
- IntelliJ Idea 常用快捷键列表 .
- ios 美元飘落效果的demo
- java.lang.IllegaAccessError:Class ref in pre-verified class resoved to unexpected implementation