CopyTo() Coppying form one array to another.


I want to understgand the CopyTo() Method. I tried to do this:

$path2 = @(“C:\Users\spate\Documents\SampleFile17.txt”)

$folder2 =@(“C:\Users\spate\Documents\SampleFile10.txt”)

I want to copy $folder2 to $path2

$folder2.CopyTo(“C:\Users\spate\Documents\SampleFile10.txt” + $path2)

not working.





Hello @sunny123,
You are trying to use String.CopyTo() method to copy file to a folder.
CopyTo(Int32, Char[], Int32, Int32) - Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.

To copy file to a folder you should use Copy-Item.

Copy-Item -Path "C:\Logfiles\logfile1.log" -Destination "C:\Drawings\Logs" 


Hope that helps.