Page 1 of 1

How to get rid of The file cannot be copied onto itself.

Posted: 09 Jun 2022 13:05
by goodywp
Hi ALl,

I have a below code to copy all subfolders files to one newly made subfolder.
folder/
    /Sub1
      /sub2
        /sub3
        .......
          /subfolder

          Code: Select all

          for /r "folder" %%d in (*) do copy "%%d" "folder\subfolder"
          
          It works fine except in the middle having these lines
          The file cannot be copied onto itself.
          0 file(s) copied.

          How can I get rid of these lines?

          Thanks

          Re: How to get rid of The file cannot be copied onto itself.

          Posted: 09 Jun 2022 16:06
          by ShadowThief
          Stick a 2>nul at the end of the line to hide the errors

          Re: How to get rid of The file cannot be copied onto itself.

          Posted: 15 Jun 2022 02:14
          by penpen
          You should copy your files to a temporary folder (preferably on the same volume) and then move them to the final location.

          penpen

          Re: How to get rid of The file cannot be copied onto itself.

          Posted: 22 Aug 2022 11:40
          by goodywp
          Thanks I will take Stick a 2>nul at the end of the line to hide the errors