Pretty sure the issue is that the 0
element in $args
is not expanding in the string creating an invalid path. Wrap the variable in $()
to allow it to expand inside a double quoted string. Else you would end up trying to copy the folder C:\TEST[0]/
which obviously is not correct.
Copy-Item -Path "$($args[0])/" -Filter *.* -Recurse
Not yet sure why you have a forward slash in there since Windows pathing uses backslashes.
function Copy-Something(){
test-Path "$($args[0])/"
test-path "$($args[0])"
}
Copy-Something C:\temp
With what little you have provided the output shows that it might be redundant to have the slash there. Would also recommend calling Test-Path
on the argument anyway as it might have caught this for you.
True
True
From Question Comment
You are looking for the -Recurse
parameter if you also want folder contents.
From Answer Comment
If you want the contents and not the folder you should be able to do something like this:
Copy-Item -Path "$($args[0])\*" -Filter *.* -Recurse