简体   繁体   中英

Why can't rename file?

My code rename file in 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. 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.

I´m using: VS2013, .NET Framework 4.0, Windows 8.1

My.Computer.FileSystem.RenameFile cannot be used to move a file to a new location. To enforce this, the new name parameter cannot contain path information and cannot end in a \\ . If the file parameter exists, then as you have it now you should get an ArgumentException with a message of:

Argument 'newName' must be a name, and not a relative or absolute path

To fix this, you simply do not include the path in your newFile parameter:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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