locked
Need to copy files to path that contains a wildcard!??! RRS feed

  • Question

  • Afternoon,

    I am attempting to copy a set of files to multiple computers on the network (files are at a dfs link, no issue there).

    The destination path on each computer is either:

    
    "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS"
    OR
    \\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS"

    The paths both have a "." in them. It is called a "middle dot" I think. It is centered between the two wordsin the path...When I run test-path it can see the path. However when I attempt to copy files to it, I get the "illegal characters in path" error.

    Below is the script I am working to get right, I hope)..

    $file = "\\path\to\files\ITClientBuild\Specs2\specslas5\testcopy.txt"
    $outfile = "c:\temp\las6copy.csv"
    gc c:\temp\las6.txt | %{
    $computer = $_
    $ping = Test-Connection $computer -Count 2 -Quiet
    if ($ping) {
    	$pathTest1 = Test-Path "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS"
    	$pathTest2 = Test-Path "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS"
    	if($pathTest1 -eq $true){
    #		md -Force "\\$computer\c$\windows\temp\las5a"
    #		cp -force "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS\las6cust.pbd" "\\$computer\c$\windows\temp\las5\*"
            cp -force $file "\\$computer\\c$\\Program Files\\AASHTOWare\\Trns·port Client-Server PES-LAS\\*"
    		"$computer	FILE PUSHED to PES-LAS dir" >> $outfile
    
    	}
    	else {"$computer	las6 PATH DOES NOT EXIST!!" >> $outfile }
    	if ($pathTest2 -eq $true){
    #		md -Force "\\$computer\c$\windows\temp\las5a"
    #		cp -force "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS\las6cust.pbd" "\\$computer\c$\windows\temp\las5\*"
    		cp -force $file "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS\*"
    
    		"$computer	FILE PUSHED to PES-LAS dir" >> $outfile
    
    	}
    	else {"$computer	PES-LAS PATH DOES NOT EXIST!!" >> $outfile }
    }
    else {"$computer	OFFLINE" >> $outfile }
    }

    My end need is to:

    Create a folder on the destination workstations, copy the original file(s) to that folder, copy the newer file(s) to the paths indicated..I have had no issues previously with copying files via powershell. However this is my first time running up against this issue.

    Your assistance is greatly appreciated...(Note: I am fairly new at this...but learning all the time)

    Tony.

    
    • Moved by Bill_Stewart Wednesday, July 9, 2014 2:18 PM Abandoned drive-by question
    Monday, March 31, 2014 7:11 PM

All replies

  • A destination path cannot have wild cards.  This is a global restriction in the Windows API.

    It also doesn't make any sense.


    ¯\_(ツ)_/¯

    Monday, March 31, 2014 7:17 PM
  • That dot character has nothing to do with the error.  The problem is the trailing "\*" you put in your destination argument to Copy-Item.  Just get rid of the * character and you should be fine.
    Monday, March 31, 2014 7:27 PM
  • Some reformatting of you file and removing a lot of the unnecessary and unused lines makes it easier to see where your mistakes are.  There are a few obvious ones.

    $file = "\\path\to\files\ITClientBuild\Specs2\specslas5\testcopy.txt"
    
    $outfile = "c:\temp\las6copy.csv"
    
    Get-Content c:\temp\las6.txt | 
        ForEach-Object{
            $computer = $_
            if(Test-Connection $computer -Count 2 -Quiet){
                if(Test-Path "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS"){
                    Copy-Item -Path $file -Destination "\\$computer\c$\Program Files\AASHTOWare\Trns·port Client-Server PES-LAS"
                    Out-File "$computer	FILE PUSHED to PES-LAS dir" -FilePath $outfile -append
                }else{
                    Out-File "$computer	las6 PATH DOES NOT EXIST!!" -FilePath $outfile -Append
                }
    
                if(Test-Path "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS")
                    Copy-Item -Path $file -Destination "\\$computer\c$\Program Files (x86)\AASHTOWare\Trns·port Client-Server PES-LAS"
                    Out-File "$computer	FILE PUSHED to PES-LAS dir" >> $outfile
                }else{
                    Out-File "$computer	PES-LAS PATH DOES NOT EXIST!!"  -FilePath $outfile -Append
                }
            }else{
                Out-File "$computer	OFFLINE"  -FilePath $outfile -Append
            }
        }


    ¯\_(ツ)_/¯

    Monday, March 31, 2014 7:29 PM
  • David - there are other problems.

    I was reactin also to this: "The paths both have a "." in them. It is called a "middle dot" I think. It is centered between the two wordsin the path...When I run test-path it can see the path. However when I attempt to copy files to it, I get the "illegal characters in path" error."

    A dot in a  folder name is completely OK.  Multiple \ and wildcards are not.

    The bigger issue is that your code is very hard to read as you are formatting it.  It is hard for you to se the errors for the code.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, March 31, 2014 7:34 PM
    Monday, March 31, 2014 7:32 PM
  • THis little thing: "Trns·port Client-Server"  is also an illegal character but will work if in quotes.  You really should not use it in a path name.  You will discover why if you try to move files and folders into the cloud.


    ¯\_(ツ)_/¯

    Monday, March 31, 2014 7:36 PM