Difference between revisions of "Move files to directory"
From MyWiki
(Created page with "<source lang="powershell"> $rootpath="c:\scripts\frances" $destpath="c:\scripts\frances\output" foreach($f in Get-Childitem $rootpath) { foreach ($i in Get-childitem $f)...") |
(No difference)
|
Latest revision as of 14:37, 3 August 2018
$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 } } }