Move files to directory

From MyWiki
Jump to: navigation, search
$rootpath="c:\scripts\frances"
$destpath="c:\scripts\frances\output"
foreach($f in Get-Childitem $rootpath)
{
 
 
    foreach ($i in Get-childitem $f)
    {
 
       if(TEst-Path $i -include *.trg)
       {
          echo($i.name + " file exists")
          $b = $i.name
          write-host("the name is $b")
          $first = $b -Split('\.')
          write-host ("the first bit is " + $first[0])
          $name = $first[0]+".csv"
          write-host $name
          Move-Item  -Path $rootpath\$name -Destination $destpath\$name
          Move-Item  -Path $rootpath\$b -Destination $destpath\$b
         exit
       }
 
    }
 
 
 
 
 
 
 
}