Skip to content

Instantly share code, notes, and snippets.

@naturallucky
Last active August 3, 2022 20:17
Show Gist options
  • Save naturallucky/7fecd5592ac9d81400615ef12a9137f9 to your computer and use it in GitHub Desktop.
Save naturallucky/7fecd5592ac9d81400615ef12a9137f9 to your computer and use it in GitHub Desktop.
PowerShell
#usage
# ./updateFile.ps1 ... before check
# or
# ./updateFile.ps1 cp ... copy
#copy from (if new)
$dir1="C:\AllFolder\xxx"
#copy to
$dir2="\\wsl$\Ubuntu\opt\xxx"
$ofiles = Get-ChildItem $dir1 -include *.css,*.xhtml -Recurse -Name
[int]$cnt = 0;
foreach($f in $ofiles){
#Write-Host("$dir1\$f")
if($(gp "$dir1\$f").LastWriteTime -gt $(gp "$dir2\$f").LastWriteTime){
if ($args[0] -eq "cp"){
cp "$dir1\$f" "$dir2\$f"
Write-Host("cp $f")
}else{
Write-Host("$dir1\$f")
} $cnt = $cnt + 1;
}
}
if ($cnt -eq 0){
Write-Host("no match")
}else{
Write-Host("$cnt file(s) copied.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment