Numerous fixes + a new command
+= ConvertTo-Zip - autodetects unrar, prefers it on 7-zip - resolves issues with some RAR extraction methods 7-zip does not support += Invoke-ExpressionEx - Added suppot for -WhatIf switch ++ Move-3Way - folder content comparative duplication was written to normalize a comics media folder == Moved aliases to base, they were wrongly created in docker.
This commit is contained in:
parent
f5e1f3e9af
commit
79e85bb21d
8 changed files with 98 additions and 14 deletions
1
base/Aliases/cp.ps1
Normal file
1
base/Aliases/cp.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Copy-Item
|
1
base/Aliases/edc.ps1
Normal file
1
base/Aliases/edc.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Edit-MyConfig
|
1
base/Aliases/eds.ps1
Normal file
1
base/Aliases/eds.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Edit-MyScript
|
1
base/Aliases/mv.ps1
Normal file
1
base/Aliases/mv.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Move-Item
|
1
base/Aliases/rm.ps1
Normal file
1
base/Aliases/rm.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Remove-Item
|
56
base/Move-3Way.ps1
Normal file
56
base/Move-3Way.ps1
Normal file
|
@ -0,0 +1,56 @@
|
|||
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='Medium')]param(
|
||||
[string]$BasePath,
|
||||
[Parameter(Mandatory,Position=1)]
|
||||
[string]$SourcePath,
|
||||
[Parameter(Mandatory,Position=2)]
|
||||
[string]$DestinationPath,
|
||||
$Logic = @(@{ FilterScript = { $flase } }),
|
||||
[ScriptBlock]$SrcTransform,
|
||||
[switch]$NonRecursive,
|
||||
[switch]$NoPassThru,
|
||||
$SubtitutionTable,
|
||||
[int]$Limit,
|
||||
[Alias("Do")]
|
||||
[switch]$NoSimulate
|
||||
)
|
||||
|
||||
$SourcePath = Join-Path $SourcePath '.' | Get-Item | Select-Object -ExpandProperty FullName
|
||||
if( $BasePath ) {
|
||||
$BasePath = Join-Path $BasePath '.' | Get-Item | Select-Object -ExpandProperty FullName
|
||||
} else {
|
||||
$BasePath = $SourcePath
|
||||
}
|
||||
$DestinationPath = Join-Path $DestinationPath '.' | Get-Item | Select-Object -ExpandProperty FullName
|
||||
|
||||
if( -not (Test-Path $BasePath,$SourcePath) ) {
|
||||
throw "Path does not exist"
|
||||
}
|
||||
|
||||
$local:limitParam = @{}
|
||||
if( $Limit ) { $limitParam.First = $Limit }
|
||||
|
||||
Get-ChildItem -LiteralPath $BasePath -File -Recurse | Where-Object {
|
||||
foreach( $local:condition in $Logic ) {
|
||||
if( -not ($_ | Where-Object @condition) ) {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
$true
|
||||
} | Sort-Object -Property FullName |
|
||||
Select-Object @limitParam | ForEach-Object {
|
||||
$local:srcPath = $_.FullName
|
||||
if( $PSBoundParameters.ContainsKey('SrcTransform') ) { $srcPath = Invoke-Command $SrcTransform -ArgumentList @($_) }
|
||||
$local:path = (Split-Path -Parent $srcPath.Replace($BasePath,'')) -replace '^[/\\]',''
|
||||
$local:dstPath = Join-Path $DestinationPath $path $(Split-Path -Leaf $srcPath)
|
||||
foreach( $local:s in $SubtitutionTable.Keys ) {
|
||||
$dstPath = $dstPath -replace $s, $SubtitutionTable[$s]
|
||||
}
|
||||
if( $srcPath -ceq $dstPath ) { continue }
|
||||
if( $NoSimulate ) {
|
||||
# Create destination path if it doesn't exists
|
||||
$null = New-Item -ItemType Directory -Path $(Join-Path $DestinationPath $path) -Force
|
||||
Move-Item -LiteralPath $srcPath -Destination $dstPath
|
||||
} else {
|
||||
"in $path found: $($_.Name)`nmove : $srcPath`nto +-> $dstPath"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue