Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange copy-item behavior 1

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
i have an array of strings representing files to copy. each one needs to be copied to a central location. i have code like...

Code:
foreach ($file in $files)
{
    write-host "copying $file";
    copy-item -path $file -destination $targetFolder
}

the content for $file might look like "\\server\folder\file name.msi" and the content for $targetFolder would be something like "c:\temp"

the problem is that the copy-item command keeps failing with an error about invalid characters in path. it then shows the path to be a concatenation of the "path" and "destination", for example "c:\temp\\server\folder\file name.msi". if i use copy-item with the strings manually entered it works fine. i have confirmed the content of the variables $file and $targetFolder. but if i use copy-item with the variables it fails!?

any thoughts on why?

thanks,

glenn
 
never mind. i figured it out. i was enclosing the individual strings in the array in quotes (due to spaces in some file names) and this was causing the "path" to get interpreted as a relative path, so the current directory was getting appended to the path resulting in the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top