简体   繁体   English

为什么不能重命名文件?

[英]Why can't rename file?

My code rename file in vb.Net: 我在vb.Net中的代码重命名文件:

Dim strFilename ="D:\2014\RF見本_P330_115%11.ai"
Dim newfile="D:\2014\RF見本_P330_115_11.ai"
My.Computer.FileSystem.RenameFile(strFilename , newfile)

But it occur error: Unable to find the specified file. 但是它发生错误: Unable to find the specified file. Why? 为什么? How can rename this file? 如何重命名该文件? Thanks all. 谢谢大家

The problem can be related to other things than the language/instruction. 该问题可能与语言/说明之外的其他问题有关。 I created the same structure here and the copy was performed normally. 我在这里创建了相同的结构,并且复制正常执行。

Check if the file has some special settings (like READONLY, PROTECTED and so forth) and if you HAVE the priviledges to access it and its folder. 检查文件是否具有某些特殊设置(例如READONLY,PROTECTED等),以及是否具有访问文件及其文件夹的特权。

I´m using: VS2013, .NET Framework 4.0, Windows 8.1 我使用的是:VS2013,.NET Framework 4.0,Windows 8.1

My.Computer.FileSystem.RenameFile cannot be used to move a file to a new location. My.Computer.FileSystem.RenameFile不能用于将文件移动到新位置。 To enforce this, the new name parameter cannot contain path information and cannot end in a \\ . 要执行此操作,新的name参数不能包含路径信息,并且不能以\\结尾。 If the file parameter exists, then as you have it now you should get an ArgumentException with a message of: 如果file参数存在,那么现在应该拥有一个带有以下消息的ArgumentException

Argument 'newName' must be a name, and not a relative or absolute path 参数“ newName”必须是名称,而不是相对或绝对路径

To fix this, you simply do not include the path in your newFile parameter: 要解决此问题,您只需在newFile参数中不包括路径:

Dim strFilename ="D:\2014\RF見本_P330_115%11.ai"
Dim newfile="RF見本_P330_115_11.ai"
My.Computer.FileSystem.RenameFile(strFilename , newfile)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM