58 file already exists




















Personally, I think you should test for the existence of the destination folder prior to. MoveFile via. FolderExists AND test for the existence of the source file in destination prior to. Testing these two scenarios will at least this care of two of the situations that will inevitably occur. I put some code below for you to reference. Best, Matt. FileExists Source Then 'move the file. I tried passing the value of I into the public sub as a long, but then I did this.

Error 58, file already exists - why? Reply to author. Report message as abuse. Show original message. Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message. I am trying to move a file from one folder to another - or at least copy and delete the old file.

Hi , Can you post the complete code? Hi , If you just wish to ignore the errors , then see if this works : Code:. GetFolder mydir. Files If objFile. Deepak Excel Ninja. Rui, This will also do the same job.. With CreateObject "Scripting. Hi Deepak, the code worked well Once again thanks for your support. Rui Pires said:. You must log in or register to reply here. The Investigation fso. MoveFile At first glance it seems like fso. MoveFile is the way to go, but it's not so simple.

The first issue is that if there are no files in source, an error will occur: solved with If. The second worse issue is that if a file already exists in destination you cannot be sure what will be copied, before an error occurs: not solved. Off course, if you know that destination is empty, or at least there aren't any existing files, this is the more efficient way.

But I wouldn't bet on it. Move The fso. Move solution has to loop through files. But you don't need to check the files count and you can implement If Not. Name Then to check the existence of a file with the same name in destination. ToPath has to end with the PathSeparator , but can optionally be followed by the file name fsoFile. Value With CreateObject "Scripting. FileSystemObject" If. FolderExists FromPath And. Print "At least one of the folders does not exist. Files If Not.

Name Then fsoFile. Name 'Else ' File already exists. Improve this answer. VBasic VBasic Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.



0コメント

  • 1000 / 1000