Last active
June 19, 2024 07:04
-
-
Save blockspacer/94e215d5b776fd92f02d7c395161b478 to your computer and use it in GitHub Desktop.
Powershell `unzip.ps1` - unzip all in folder. `movebetween.ps1` - move files from folder with names matching contents of other folder. `movelonedirs.ps1` - move subdirs at upper level and remove empty subdirs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
for file in *; do | |
if [ -d "$file" ]; then | |
# Will not run if no directories are available | |
echo mv "$file" "${file//[ .()@$]/_}" | |
mv "$file" "${file//[ .()@$]/_}" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] param () # https://stackoverflow.com/a/69203862 | |
function Measure-StringDistance { | |
<# | |
.SYNOPSIS | |
Compute the distance between two strings using the Levenshtein distance formula. | |
.DESCRIPTION | |
Compute the distance between two strings using the Levenshtein distance formula. | |
.PARAMETER Source | |
The source string. | |
.PARAMETER Compare | |
The comparison string. | |
.EXAMPLE | |
PS C:\> Measure-StringDistance -Source "Michael" -Compare "Micheal" | |
2 | |
There are two characters that are different, "a" and "e". | |
.EXAMPLE | |
PS C:\> Measure-StringDistance -Source "Michael" -Compare "Michal" | |
1 | |
There is one character that is different, "e". | |
.NOTES | |
Author: | |
Michael West | |
#> | |
[CmdletBinding(SupportsShouldProcess=$true)] | |
[OutputType([int])] | |
param ( | |
[Parameter(ValueFromPipelineByPropertyName=$true)] | |
[string]$Source = "", | |
[string]$Compare = "" | |
) | |
$n = $Source.Length; | |
$m = $Compare.Length; | |
$d = New-Object 'int[,]' $($n+1),$($m+1) | |
if ($n -eq 0){ | |
return $m | |
} | |
if ($m -eq 0){ | |
return $n | |
} | |
for ([int]$i = 0; $i -le $n; $i++){ | |
$d[$i, 0] = $i | |
} | |
for ([int]$j = 0; $j -le $m; $j++){ | |
$d[0, $j] = $j | |
} | |
for ([int]$i = 1; $i -le $n; $i++){ | |
for ([int]$j = 1; $j -le $m; $j++){ | |
if ($Compare[$($j - 1)] -eq $Source[$($i - 1)]){ | |
$cost = 0 | |
} | |
else{ | |
$cost = 1 | |
} | |
$d[$i, $j] = [Math]::Min([Math]::Min($($d[$($i-1), $j] + 1), $($d[$i, $($j-1)] + 1)),$($d[$($i-1), $($j-1)]+$cost)) | |
} | |
} | |
return $d[$n, $m] | |
} | |
function Levenshtein-StringDistance { | |
[CmdletBinding(SupportsShouldProcess=$true)] | |
[OutputType([int])] | |
# get-ld.ps1 (Levenshtein Distance) | |
# Levenshtein Distance is the # of edits it takes to get from 1 string to another | |
# This is one way of measuring the "similarity" of 2 strings | |
# Many useful purposes that can help in determining if 2 strings are similar possibly | |
# with different punctuation or misspellings/typos. | |
# | |
######################################################## | |
# Putting this as Source non comment or empty line declares the parameters | |
# the script accepts | |
########### | |
param([string] $Source, [string] $Compare, [switch] $ignoreCase) | |
# No NULL check needed, why is that? | |
# PowerShell parameter handling converts Nulls into empty strings | |
# so we will never get a NULL string but we may get empty strings(length = 0) | |
######################### | |
$len1 = $Source.length | |
$len2 = $Compare.length | |
# If either string has length of zero, the # of edits/distance between them | |
# is simply the length of the other string | |
####################################### | |
if($len1 -eq 0) | |
{ return $len2 } | |
if($len2 -eq 0) | |
{ return $len1 } | |
# make everything lowercase if ignoreCase flag is set | |
if($ignoreCase -eq $true) | |
{ | |
$Source = $Source.tolowerinvariant() | |
$Compare = $Compare.tolowerinvariant() | |
} | |
# create 2d Array to store the "distances" | |
$dist = new-object -type 'int[,]' -arg ($len1+1),($len2+1) | |
# initialize the Source row and Source column which represent the 2 | |
# strings we're comparing | |
for($i = 0; $i -le $len1; $i++) | |
{ $dist[$i,0] = $i } | |
for($j = 0; $j -le $len2; $j++) | |
{ $dist[0,$j] = $j } | |
$cost = 0 | |
for($i = 1; $i -le $len1;$i++) | |
{ | |
for($j = 1; $j -le $len2;$j++) | |
{ | |
if($Compare[$j-1] -ceq $Source[$i-1]) | |
{ | |
$cost = 0 | |
} | |
else | |
{ | |
$cost = 1 | |
} | |
# The value going into the cell is the min of 3 possibilities: | |
# 1. The cell immediately above plus 1 | |
# 2. The cell immediately to the left plus 1 | |
# 3. The cell diagonally above and to the left plus the 'cost' | |
############## | |
# I had to add lots of parentheses to "help" the Powershell parser | |
# And I separated out the tempmin variable for readability | |
$tempmin = [System.Math]::Min(([int]$dist[($i-1),$j]+1) , ([int]$dist[$i,($j-1)]+1)) | |
$dist[$i,$j] = [System.Math]::Min($tempmin, ([int]$dist[($i-1),($j-1)] + $cost)) | |
} | |
} | |
# the actual distance is stored in the bottom right cell | |
return $dist[$len1, $len2]; | |
} | |
# https://dejanstojanovic.net/powershell/2018/february/merge-folders-with-windows-powershell-script/ | |
function MergeDirsByDiff | |
{ | |
[CmdletBinding(SupportsShouldProcess=$true)] | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$sourcePath, | |
[Parameter(Mandatory=$true)] | |
[string]$destinationPath, | |
[switch] $Recurse | |
) | |
# https://www.sqlhammer.com/compare-paths-with-powershell/ | |
$sourcePath = Join-Path "$sourcePath" '' | |
$destinationPath = Join-Path "$destinationPath" '' | |
#$files = Get-ChildItem -Path $sourcePath -Recurse -Filter "*" | |
[System.Collections.ArrayList]$files = @( | |
#$(Get-ChildItem -LiteralPath $sourcePath -Recurse | sort -Descending) | |
$(Get-ChildItem -LiteralPath $sourcePath | sort -Descending) | |
) | |
Write-Verbose "MergeDirsByDiff sourcePath=$sourcePath destinationPath=$destinationPath files=$files" | |
foreach($file in $files){ | |
$sourcePathFile = $file.FullName | |
$destinationPathFile = $file.FullName.Replace($sourcePath, $destinationPath) | |
#sourcePathFile=G:\downloads\test\1\test2test\test2test | |
#destinationPath=G:\downloads\test\1\test1test\Новый текстовый документ.txt | |
#destinationPathFile=G:\downloads\test\1\test1test\Новый текстовый документ.txttest2test | |
$exists = Test-Path $destinationPathFile | |
$isFile = Test-Path -LiteralPath $sourcePathFile -PathType Leaf | |
$isFolder = Test-Path -LiteralPath $sourcePathFile -PathType Container | |
Write-Verbose "MergeDirsByDiff sourcePath=$sourcePath sourcePathFile=$sourcePathFile destinationPath=$destinationPath destinationPathFile=$destinationPathFile file.FullName=$sourcePathFile isFile=$isFile isFolder=$isFolder" | |
if(!$exists) | |
{ | |
Write-Verbose "MergeDirsByDiff new path=$destinationPathFile" | |
$dir = Split-Path -parent $destinationPathFile | |
if (!(Test-Path($dir))) { | |
Write-Verbose "MergeDirsByDiff new dir=$dir" | |
New-Item -ItemType directory -Path $dir -Force -ErrorAction Continue -Verbose | |
} | |
if ($isFolder) { # copy folder into new folder that did not exist before | |
if (!(Test-Path($destinationPathFile))) { | |
Write-Verbose "MergeDirsByDiff new dir=$dir" | |
New-Item -ItemType directory -Path $destinationPathFile -Force -ErrorAction Continue -Verbose | |
} | |
if ("$sourcePathFile" -eq "$sourcePath") { | |
throw "infinite recursion! $sourcePathFile == $sourcePath" | |
} | |
if ("$destinationPathFile" -eq "$destinationPath") { | |
throw "infinite recursion! $destinationPathFile == $destinationPath" | |
} | |
Write-Host "Merging folder sourcePathFile=$sourcePathFile into destinationPathFile=$destinationPathFile" | |
MergeDirsByDiff -sourcePath "$sourcePathFile" -destinationPath "$destinationPathFile" -Recurse | |
#Copy-Item -LiteralPath "$sourcePathFile/*" -Destination "$destinationPathFile" -Recurse -Force -ErrorAction Continue -Verbose | |
# without -Recurse | |
#[System.Collections.ArrayList]$toCopy = @( | |
# $(Get-ChildItem -LiteralPath $sourcePathFile | sort -Descending) | |
#) | |
#Write-Host "MergeDirsByDiff toCopy=$toCopy from sourcePathFile=$sourcePathFile to #destinationPathFile=$destinationPathFile" | |
## override files and keep directory structure using "Copy-Item" | |
#$toCopy | Copy-Item -Destination "$destinationPathFile" -Recurse -Force -ErrorAction Continue -Verbose | |
} | |
if($isFile){ | |
Write-Host "MergeDirsByDiff copy file=$sourcePathFile into $destinationPathFile" | |
Copy-Item -LiteralPath "$sourcePathFile" -Destination $destinationPathFile -Recurse -Force -ErrorAction Continue -Verbose | |
} | |
} | |
else | |
{ | |
#$destinationPathItem = (Get-Item -LiteralPath "$destinationPathFile") | |
if($isFile) | |
{ | |
#$different = Compare-Object -ReferenceObject $(Get-Content $sourcePathFile) -DifferenceObject $(Get-Content $destinationPathFile) | |
#if(Compare-Object -ReferenceObject $(Get-Content $sourcePathFile) -DifferenceObject $(Get-Content $destinationPathFile)) | |
#{ | |
# Write-Verbose "MergeDirsByDiff different file=$destinationPathFile" | |
# $dir = Split-Path -parent $destinationPathFile | |
# if (!(Test-Path($dir))) | |
# { | |
# New-Item -ItemType directory -Path $dir -Force -ErrorAction Continue -Verbose | |
# } | |
# Copy-Item -LiteralPath "$sourcePathFile" -Destination $destinationPathFile -Recurse -Force -ErrorAction Continue -Verbose | |
#} else { | |
# Write-Warning "MergeDirsByDiff skip, same diff of file=$destinationPathFile" | |
#} | |
Copy-Item -LiteralPath "$sourcePathFile" -Destination $destinationPathFile -Recurse -Force -ErrorAction Continue -Verbose | |
} | |
if ($isFolder) { # copy folder into new folder that existed before | |
if ("$sourcePathFile" -eq "$sourcePath") { | |
throw "infinite recursion! $sourcePathFile == $sourcePath" | |
} | |
if ("$destinationPathFile" -eq "$destinationPath") { | |
throw "infinite recursion! $destinationPathFile == $destinationPath" | |
} | |
Write-Host "Merging folder sourcePathFile=$sourcePathFile into destinationPathFile=$destinationPathFile" | |
MergeDirsByDiff -sourcePath "$sourcePathFile" -destinationPath "$destinationPathFile" -Recurse | |
} | |
} | |
} | |
} | |
#function MergeDirsByDiffRecursion | |
#{ | |
# [CmdletBinding(SupportsShouldProcess=$true)] | |
# Param( | |
# [Parameter(Mandatory=$true)] | |
# [string]$sourcePath, | |
# [Parameter(Mandatory=$true)] | |
# [string]$destinationPath, | |
# [switch] $removeEmptyFolders | |
# ) | |
# | |
# # https://www.sqlhammer.com/compare-paths-with-powershell/ | |
# $sourcePath = Join-Path "$($sourcePath)" '' | |
# $destinationPath = Join-Path "$($destinationPath)" '' | |
# | |
# [System.Collections.ArrayList]$folderStructure = @( | |
# $(Get-ChildItem -LiteralPath $sourcePath -Directory -Recurse | sort -Descending) | |
# ) | |
# Write-Host "MergeDirsByDiffRecursion sourcePath=$sourcePath destinationPath=$destinationPath #folderStructure=$folderStructure" | |
# | |
# foreach ($childDirectory in $folderStructure) | |
# { | |
# $dest = $childDirectory.FullName.Replace($sourcePath, $destinationPath) | |
# Write-Host "MergeDirsByDiffRecursion childDirectory=$($childDirectory.FullName) dest=$dest" | |
# MergeDirsByDiff -sourcePath $($childDirectory.FullName) -destinationPath $dest -Recurse | |
# } | |
# MergeDirsByDiff -sourcePath $sourcePath -destinationPath $destinationPath -Recurse | |
# $currentChildren = Get-ChildItem -Force -LiteralPath $sourcePath -ErrorAction Continue | |
# if ($removeEmptyFolders -eq $true) | |
# { | |
# $isEmpty = $currentChildren -eq $null | |
# if ($isEmpty) { | |
# # remove empty folders | |
# Write-Host "Remove-Item=$sourcePath" | |
# Remove-Item -Force -LiteralPath $sourcePath | |
# } | |
# } | |
#} | |
function MergeSimilarSubdirs { | |
[CmdletBinding(SupportsShouldProcess=$true)] | |
[OutputType([int])] | |
param([string] $inputFolder, [string[]] $inDirs) | |
if ($inDirs.Count -eq 0) { | |
return 0 | |
} | |
$mergedC = 0 | |
$inputDirs = $inDirs | % { Get-Item -LiteralPath "$_" } | sort | |
Write-Host "inputDirs=$inputDirs" | |
for($index = 0; $index -lt $inputDirs.Count - 1; $index++) | |
{ | |
$curr = $index | |
$next = $index+1 | |
$sourceStr = $inputDirs[$curr].Name.ToLower() | |
$otherStr = $inputDirs[$next].Name.ToLower() | |
$lenMax = [Math]::Max($sourceStr.length,$otherStr.length) | |
if ($lenMax -lt 3) { | |
# skip short names | |
} else { | |
$dist = Levenshtein-StringDistance -Source $sourceStr -Compare $otherStr | |
$diffPct = $dist / $lenMax | |
Write-Verbose "DeiffEdits=$dist/$lenMax diffPct=$diffPct sourceStr=$sourceStr otherStr=$otherStr sourceStr.length=$($sourceStr.length)" | |
$reqPct = 0.12 | |
if ($lenMax -gt 5) { | |
$reqPct = 0.23 | |
} | |
if ($lenMax -gt 20) { | |
$reqPct = 0.34 | |
} | |
if ($diffPct -le $reqPct) { # similar | |
$mergedC = $mergedC + 1 | |
Write-Host "Merging similar folder names StringDistance=$dist diffPct=$diffPct sourceStr=$sourceStr otherStr=$otherStr" | |
# override files and keep directory structure using "Copy-Item" | |
#Get-ChildItem -Path "$($inputDirs[$next].FullName)/" | Copy-Item -Destination $targetDir -Recurse -Container -Verbose -Force -ErrorAction Continue | |
# NOTE: Move-Item fails to move folder contents if folder with same name exists in destination, | |
# so had to use Copy-Item above | |
#Move-Item -Path "$($inputDirs[$next].FullName)/*" -Destination "$($inputDirs[$curr].FullName)/" -Verbose -Force -ErrorAction Continue -ErrorVariable $moveItemError | |
MergeDirsByDiff -sourcePath "$($inputDirs[$next].FullName)" -destinationPath "$($inputDirs[$curr].FullName)" -Recurse | |
#if ($moveItemError) { | |
# Write-Warning "Warning, failed to move $($inputDirs[$next].FullName)/* into $($inputDirs#[$curr].FullName)/" | |
#} else { | |
# Write-Host "removing $($inputDirs[$next].FullName)" | |
# Remove-Item -Force -LiteralPath "$($inputDirs[$next].FullName)" -Recurse | |
#} | |
Write-Host "removing $($inputDirs[$next].FullName)" | |
Remove-Item -Force -LiteralPath "$($inputDirs[$next].FullName)" -Recurse | |
#$index = $index + 1 # folder with $next does not exist anymore | |
# dir does not exist enymore, remove from array | |
[array] $newInputDirs = $inputDirs | Where { "$($_.FullName)" -ne "$($inputDirs[$next].FullName)" } | sort #| Where-Object { [array]::IndexOf($inputDirs, $_) -ne $next } | |
# re-run with new array data | |
$inFolders = $newInputDirs | % { $_.FullName } | sort | |
MergeSimilarSubdirs -inputFolder $inputFolder -inDirs $inFolders | |
break | |
} | |
} | |
} | |
if($mergedC -le 0) { | |
Write-Host "final inputDirs=$inputDirs" | |
} | |
return $mergedC | |
} | |
$inputFolder = "$($pwd.Path)" | |
[System.Collections.ArrayList]$inputDirs = @( | |
$(Get-ChildItem -Path $inputFolder -Directory) | |
) | |
if ($inputDirs.Count -eq 0) { | |
exit 0 | |
} | |
if (-not (Test-Path -Path $inputFolder -PathType container)) { | |
throw "'$inputFolder' not found" | |
} | |
# NOTE: sort Ascending to move into folder with shorter name | |
[System.Collections.ArrayList]$inputDirs = @( | |
$(Get-ChildItem -Path $inputFolder -Directory | sort) | |
) | |
$inFolders = $inputDirs | % { $_.FullName } | sort | |
#Write-Host "inFolders=$inFolders" | |
MergeSimilarSubdirs -inputFolder $inputFolder -inDirs $inFolders | |
#Write-Host "inputDirs=$($inputDirs)" | |
#exit 0 | |
#$attempt = 0 | |
#$attemptsMax = 1#$inputDirs.Count / 2 + 1 | |
#while ($attempt -lt $attemptsMax) | |
#{ | |
# Write-Host "attempt=$attempt attemptsMax=$attemptsMax" | |
# $attempt = $attempt + 1 | |
# $mergedC = MergeSimilarSubdirs -inputFolder $inputFolder | |
# if($mergedC -le 0) { | |
# break | |
# } | |
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -value 1 | |
# set-executionpolicy unrestricted | |
$inputFolder = "$($pwd.Path)" | |
if (-not (Test-Path -Path $inputFolder -PathType container)) { | |
throw "'$inputFolder' not found" | |
} | |
[System.Collections.ArrayList]$inputFiles = @( | |
$(Get-ChildItem -Path $inputFolder) | |
) | |
Write-Host "inputFiles=$($inputFiles)" | |
$filterFolder = 'D:\bitl\s28.bitdl.ir\Compresed\SKILLSHARE\' | |
if (-not (Test-Path -Path $filterFolder -PathType container)) { | |
throw "'$filterFolder' not found" | |
} | |
[System.Collections.ArrayList]$filterFiles = @( | |
$(Get-ChildItem -Path $filterFolder) | |
) | |
Write-Host "filterFiles=$($filterFiles)" | |
$outputFolder = 'D:\bitl\s28.bitdl.ir\Compresed\tmp2\' | |
If(!(test-path -PathType container $outputFolder)) | |
{ | |
# You can ignore errors in PowerShell with the | |
# -ErrorAction SilentlyContinue parameter (you can shorten this to -ea 0). | |
# stackoverflow.com/questions/47357135/powershell-equivalent-of-linux-mkdir-p | |
New-Item $outputFolder -ItemType Directory -ea 0 | |
} | |
if (-not (Test-Path -Path $outputFolder -PathType container)) { | |
throw "'$outputFolder' not found" | |
} | |
foreach ($infile in $inputFiles) | |
{ | |
if ($infile.Extension.ToLower().Equals(".ps1")) { | |
Write-Host "Extension=$($infile.FullName.ToLower())" | |
continue | |
} | |
#If(!(test-path -PathType container $infile)) | |
#{ | |
#Write-Host "not folder=$($infile.Name.ToLower())" | |
#continue | |
#} | |
Write-Host "infile=$($infile.Name.ToLower())" | |
foreach ($filterfile in $filterFiles) | |
{ | |
if ($filterfile.Extension.ToLower().Equals(".ps1")) { | |
Write-Host "Extension=$($filterfile.FullName.ToLower())" | |
continue | |
} | |
if ($infile.BaseName.ToLower().Contains("$($filterfile.BaseName.ToLower())")) { | |
Write-Host "filterfile=$($filterfile.Name.ToLower())" | |
$destination = "$($outputFolder)$($infile.Name)" | |
Write-Host "Destination=$($destination)" | |
Move-Item -Path "$($infile.FullName)" -Destination "$($destination)" -Verbose -Force -ErrorAction Stop | |
#if ($infile.DirectoryName.Name.ToLower().StartsWith($exclusion.Name.ToLower())) | |
#{ | |
# $exclude = $true | |
#} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -value 1 | |
# set-executionpolicy unrestricted | |
$inputFolder = "$($pwd.Path)" | |
if (-not (Test-Path -Path $inputFolder -PathType container)) { | |
throw "'$inputFolder' not found" | |
} | |
[System.Collections.ArrayList]$inputFiles = @( | |
$(Get-ChildItem -Path $inputFolder) | |
) | |
Write-Host "inputFiles=$($inputFiles)" | |
# https://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell | |
# A script block (anonymous function) that will remove empty folders | |
# under a root folder, using tail-recursion to ensure that it only | |
# walks the folder tree once. -Force is used to be able to process | |
# hidden files/folders as well. | |
$tailRecursion = { | |
param( | |
$Path | |
) | |
foreach ($childDirectory in Get-ChildItem -Force -LiteralPath $Path -Directory) { | |
& $tailRecursion -Path $childDirectory.FullName | |
} | |
$currentChildren = Get-ChildItem -Force -LiteralPath $Path | |
$isEmpty = $currentChildren -eq $null | |
if ($isEmpty) { | |
Write-Verbose "Removing empty folder at path '${Path}'." -Verbose | |
Remove-Item -Verbose -Force -LiteralPath $Path | |
} | |
} | |
# 10 is max subfodler depth | |
for ($i=1; $i -le 10; $i++) { | |
foreach ($infile in $inputFiles) | |
{ | |
if ($infile.Extension.ToLower().Equals(".ps1")) { | |
#Write-Host "Extension=$($infile.FullName.ToLower())" | |
continue | |
} | |
If(!(Test-Path -Path "$($infile.FullName)" -PathType Container)) | |
{ | |
Write-Host "not folder=$($infile.Name.ToLower())" | |
continue | |
} | |
#Write-Host "infile=$($infile.Name.ToLower())" | |
[System.Collections.ArrayList]$filterFiles = @( | |
$(Get-ChildItem -Path $infile) | |
) | |
#Write-Host "filterFiles=$($filterFiles)" | |
#Please note that you have to use -gt instead of > in your if condition. #PowerShell uses the following comparison operators to compare values and test conditions: | |
#-eq = equals (==) | |
#-ne = not equals (!=) | |
#-lt = less than (<) | |
#-gt = greater than (>) | |
#-le = less than or equals (<=) | |
#-ge = greater than or equals (>=) | |
#if ($filterFiles.length -gt 2) { | |
# Write-Host "length -gt 2" | |
# continue | |
#} | |
#$hasAnySubdir = (Get-ChildItem -Force -Directory $infile).Count -gt 0 | |
$hasNoFiles = !((Get-ChildItem -Force -File $infile).Count -gt 0) | |
if (($filterFiles.length -gt 2) -And ($hasNoFiles)) { | |
Write-Host "length -gt 2 & !hasAnyFile" | |
# skip dirs that consist only of (many) subfolders | |
continue | |
} | |
$hasTwoFiles = (Get-ChildItem -Force -File $infile).Count -gt 1 | |
if (($filterFiles.length -gt 2) -And ($hasTwoFiles)) { | |
Write-Host "length -gt 2 & hasTwoFiles" | |
# skip dirs with >= 2 files | |
continue | |
} | |
foreach ($filterfile in $filterFiles) | |
{ | |
if (($filterFiles.length -eq 1) -And ($hasNoFiles)) { | |
if ((Join-Path "$($inputFolder)" '') -ne (Join-Path "$($filterfile.Parent.FullName)" '')) | |
{ | |
Write-Host "length -gt 2 & !hasAnyFile" | |
Write-Host "filterfile=$($filterfile.FullName)" | |
Write-Host "filterfile.Parent=$($filterfile.Parent.FullName)" | |
# move up subfolder data from dir that consists only of 1 subfolder | |
Move-Item -Path "$($filterfile.FullName)/*" -Destination "$($filterfile.Parent.FullName)/" -Verbose -Force -ErrorAction Continue | |
#exit 0 | |
} | |
} | |
if ($filterfile.Extension.ToLower().Equals(".ps1")) { | |
Write-Host "Extension=$($filterfile.FullName.ToLower())" | |
continue | |
} | |
If(!(Test-Path -Path "$($filterfile.FullName)" -PathType Container)) | |
{ | |
Write-Host "not folder=$($filterfile.Name.ToLower())" | |
continue | |
} | |
Write-Host "filterfile=$($filterfile.FullName)" | |
$destination = "$($infile.FullName)/" | |
Write-Host "Destination=$($destination)" | |
# -ErrorAction Stop | |
Move-Item -Path "$($filterfile.FullName)/*" -Destination "$($destination)" -Verbose -Force -ErrorAction Continue | |
} | |
} | |
} | |
#Please note that you have to use -gt instead of > in your if condition. #PowerShell uses the following comparison operators to compare values and test conditions: | |
#-eq = equals (==) | |
#-ne = not equals (!=) | |
#-lt = less than (<) | |
#-gt = greater than (>) | |
#-le = less than or equals (<=) | |
#-ge = greater than or equals (>=) | |
if ($inputFolder.Length -gt 3) { | |
# delete empty folders | |
# remark that the code also removes the start folder if that winds up empty | |
& $tailRecursion -Path "$($inputFolder)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -value 1 | |
# set-executionpolicy unrestricted | |
# https://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell | |
# A script block (anonymous function) that will remove empty folders | |
# under a root folder, using tail-recursion to ensure that it only | |
# walks the folder tree once. -Force is used to be able to process | |
# hidden files/folders as well. | |
function tailRecursion($Path) | |
{ | |
foreach ($childDirectory in Get-ChildItem -Force -LiteralPath $Path -ErrorAction SilentlyContinue -Directory) { | |
tailRecursion -Path $childDirectory.FullName | |
} | |
$currentChildren = Get-ChildItem -Force -LiteralPath $Path -ErrorAction SilentlyContinue | |
$isEmpty = $currentChildren -eq $null | |
if ($isEmpty) { | |
#Write-Verbose "Removing empty folder at path '${Path}'." -Verbose | |
Remove-Item -Force -LiteralPath $Path | |
} | |
} | |
function movelonedirs($inputFolder) | |
{ | |
[System.Collections.ArrayList]$inputFiles = @( | |
$(Get-ChildItem -Force -Path $inputFolder -ErrorAction SilentlyContinue) | |
) | |
Write-Host "inputFiles=$inputFiles" | |
# 10 is max subfodler depth | |
for ($i=1; $i -le 10; $i++) { | |
foreach ($infile in $inputFiles) | |
{ | |
if ($infile.Extension.ToLower().Equals(".ps1")) { | |
#Write-Host "Extension=$($infile.FullName.ToLower())" | |
continue | |
} | |
If(!(Test-Path -Path "$($infile.FullName)" -PathType Container)) | |
{ | |
#Write-Host "not folder=$($infile.Name.ToLower())" | |
continue | |
} | |
#Write-Host "infile=$($infile.Name.ToLower())" | |
[System.Collections.ArrayList]$filterFiles = @( | |
$(Get-ChildItem -Force -Path $infile -ErrorAction SilentlyContinue) | |
) | |
#Write-Host "filterFiles=$($filterFiles)" | |
#Please note that you have to use -gt instead of > in your if condition. #PowerShell uses the following comparison operators to compare values and test conditions: | |
#-eq = equals (==) | |
#-ne = not equals (!=) | |
#-lt = less than (<) | |
#-gt = greater than (>) | |
#-le = less than or equals (<=) | |
#-ge = greater than or equals (>=) | |
#if ($filterFiles.length -gt 2) { | |
# Write-Host "length -gt 2" | |
# continue | |
#} | |
#$hasAnySubdir = (Get-ChildItem -Force -Directory $infile).Count -gt 0 | |
$hasNoFiles = !((Get-ChildItem -Force -File $infile -ErrorAction SilentlyContinue).Count -gt 0) | |
if (($filterFiles.length -gt 2) -And ($hasNoFiles)) { | |
#Write-Host "length -gt 2 & !hasAnyFile" | |
# skip dirs that consist only of subfolders | |
continue | |
} | |
$hasTwoFiles = (Get-ChildItem -Force -File $infile -ErrorAction SilentlyContinue).Count -gt 1 | |
if (($filterFiles.length -gt 2) -And ($hasTwoFiles)) { | |
#Write-Host "length -gt 2 & hasTwoFiles" | |
# skip dirs with >= 2 files | |
continue | |
} | |
foreach ($filterfile in $filterFiles) | |
{ | |
if ($filterfile.Extension.ToLower().Equals(".ps1")) { | |
#Write-Host "Extension=$($filterfile.FullName.ToLower())" | |
continue | |
} | |
If(!(Test-Path -Path "$($filterfile.FullName)" -PathType Container)) | |
{ | |
#Write-Host "not folder=$($filterfile.Name.ToLower())" | |
continue | |
} | |
#Write-Host "filterfile=$($filterfile.FullName)" | |
$destination = "$($infile.FullName)/" | |
#Write-Host "Destination=$($destination)" | |
# -ErrorAction Stop | |
Move-Item -Path "$($filterfile.FullName)/*" -Destination "$destination" -Force -ErrorAction SilentlyContinue #-Verbose | |
} | |
} | |
} | |
#Please note that you have to use -gt instead of > in your if condition. #PowerShell uses the following comparison operators to compare values and test conditions: | |
#-eq = equals (==) | |
#-ne = not equals (!=) | |
#-lt = less than (<) | |
#-gt = greater than (>) | |
#-le = less than or equals (<=) | |
#-ge = greater than or equals (>=) | |
if ($inputFolder.Length -gt 3) { | |
# delete empty folders | |
# remark that the code also removes the start folder if that winds up empty | |
tailRecursion -Path "$inputFolder" | |
} | |
} | |
function run7zbypath($arInputFolder, | |
[string[]]$arInclude, | |
[string[]]$passwords) | |
{ | |
write-host "arInputFolder=$arInputFolder" | |
write-host "arInclude=$arInclude" | |
write-host "passwords=$passwords" | |
#$WinRar = "C:\Program Files\WinRAR\WinRAR.exe" | |
#if (-not (Test-Path -Path $WinRar -PathType Leaf)) { | |
# throw "file '$WinRar' not found" | |
#} | |
#$UnRAR = "C:\Program Files\WinRAR\UnRAR.exe" | |
#if (-not (Test-Path -Path $UnRAR -PathType Leaf)) { | |
# throw "file '$UnRAR' not found" | |
#} | |
# 7-Zip Extra: standalone console version, 7z DLL, Plugin for Far Manager | |
$SZexe = "C:\Program Files\7-Zip\7z.exe" | |
if (-not (Test-Path -Path $SZexe -PathType Leaf)) { | |
throw "file '$SZexe' not found" | |
} | |
$zFiles = Get-ChildItem -Recurse -path $arInputFolder -Include $arInclude -ErrorAction SilentlyContinue | |
write-host "zFiles=$zFiles" | |
#exit 0 | |
foreach ($zFile in $zFiles) | |
{ | |
$outPutFolder = "$($zFile.DirectoryName)" | |
Write-Host "arInputFolder=$arInputFolder" | |
$isFile = Test-Path -LiteralPath $zFile -PathType Leaf | |
if(!$isFile) | |
{ | |
Write-Host "not file=$zFile" | |
continue | |
} | |
$zDir = $zFile.Directory.FullName | |
Write-Host "Directory=$zDir" | |
$isFolder = Test-Path -LiteralPath $zDir -PathType Container | |
if(!$isFolder) | |
{ | |
Write-Host "not folder=$zDir" | |
continue | |
} | |
$outPutSubFolder = "" | |
# https://www.sqlhammer.com/compare-paths-with-powershell/ | |
if ((Join-Path "$arInputFolder" '') -eq (Join-Path "$zDir" '')) { | |
$outPutSubFolder = "$($zFile.BaseName -replace '\.part\d*$')\" | |
} | |
#$outPutFolderExtended = $outPutFolder + "\" + $zFile.BaseName | |
# Use regex to remove the ‘part#’ part. | |
#https://stackoverflow.com/a/31784829 | |
$outPutFolderExtended = "$outPutFolder\$($outPutSubFolder.subString(0, [System.Math]::Min(50, $outPutSubFolder.Length)) -replace "\W")" | |
$exists = Test-Path $outPutFolderExtended | |
if($exists) | |
{ | |
Write-Host "will extract into already existing folder=$outPutFolderExtended" | |
} | |
#Expand-Archive -Path "$($zFile.FullName)" -DestinationPath $outPutFolderExtended | |
foreach ($password in $passwords) | |
{ | |
Write-Host $password | |
if ($password) { | |
&$SZexe "t" "$($zFile.FullName)" "-p$password" ; | |
if (-Not $?) | |
{ | |
Write-Host "$password is not the password." | |
} else { | |
Write-Host "$password is the password." | |
# Call 7zip. Provide password as an argument. | |
#&$SZexe x "$($zFile.FullName)" "-o$($outPutFolderExtended)" -y "-p$($password)" ; | |
$arguments=@("x", """$($zFile.FullName)""", """-o$outPutFolderExtended""", "-y", "-p$password"); | |
$ex = start-process -NoNewWindow -FilePath """$SZexe""" -ArgumentList $arguments -wait -PassThru; | |
if( $ex.ExitCode -eq 0) | |
{ | |
write-host "Extraction successful, deleting $($zFile.FullName)" | |
#rmdir -Path "$($zFile.FullName)" -Force | |
Remove-Item -Force -LiteralPath "$($zFile.FullName)" | |
} else { | |
Write-Host "Extraction failed with $($ex.ExitCode) of $($zFile.FullName)" | |
} | |
if( $outPutSubFolder.Length -ge 0) { | |
movelonedirs -inputFolder "$outPutFolderExtended" | |
} | |
break # password found | |
} | |
} else { | |
#&$SZexe x "$($zFile.FullName)" "-o$($outPutFolderExtended)" -y ; | |
#if (-Not $?) | |
#{ | |
# Write-Host "empty password string failed" | |
#} else { | |
# break # password found | |
#} | |
$arguments=@("x", """$($zFile.FullName)""", """-o$outPutFolderExtended""", "-y", "-pbitdownload.ir"); | |
$ex = start-process -NoNewWindow -FilePath """$SZexe""" -ArgumentList $arguments -wait -PassThru; | |
if( $ex.ExitCode -eq 0) | |
{ | |
write-host "Extraction successful, deleting $($zFile.FullName)" | |
#rmdir -Path "$($zFile.FullName)" -Force | |
Remove-Item -Force -LiteralPath "$($zFile.FullName)" | |
} else { | |
Write-Host "empty password string failed" | |
Write-Host "Extraction failed with $($ex.ExitCode) of $($zFile.FullName)" | |
} | |
if( $outPutSubFolder.Length -ge 0) { | |
movelonedirs -inputFolder "$outPutFolderExtended" | |
} | |
break # password found | |
} | |
} | |
} | |
} | |
# Last try is no password at all | |
# NOTE: usually any password will succeed if archive password is empty | |
$passwords = @("bitdownload.ir", "p30download.com", "bitdownload", "www.p30download.com", "p30download", "www.bitdownload.ir", "bitdownload", "bitdl", "bitdl.ir", "www.bitdl.ir", "@udemyking1", "hide01.ir", "@MDiscordBot", "@redbluehit", "XDJ", "xdj@hacksnation.com", "whocares", "brute force", "dfghgfh", "irlanguage.com", "www.irlanguage.com", "www.irLanguage.com", "www.vatandownload.com", "vatandownload.com", "www.MihanDownload.com", "www.mihandownload.com", "mihandownload.com", "https://dxschool.org", "dxschool.org", "www.dxschool.org", "www.p30forum.com", "p30forum.com", "p30forum", "www.sharewood-zerkalo.com", "sharewood-zerkalo.com", "sharewood", "SW.BAND", "supersliv.biz", "TonyPart4Four", "www.sharewood.biz", "sharewood.biz", "boominfo.ru", "infovirus.biz", "infosklad.org", "www.infosklad.org", "d3G#0N9JO*", "v1H8s38ouj9Sg9Y9rtI", "") | |
$arInclude = @("*.rar", "*.zip", "*.iso") | |
#& $run7zbypath -arInputFolder "$($pwd.Path)" -arInclude $arInclude -passwords $passwords | |
#run7zbypath("$($pwd.Path)", $arInclude, $passwords) | |
# 3 is max iterations (attempts) | |
for ($i=1; $i -le 3; $i++) { | |
run7zbypath -arInputFolder "$($pwd.Path)" -arInclude $arInclude -passwords $passwords | |
movelonedirs -inputFolder "$($pwd.Path)" | |
} | |
# https://igorpuhalo.wordpress.com/2019/08/29/overcoming-long-path-problem-in-powershell/ | |
#$zFiles = Get-ChildItem -Recurse -path $arInputFolder -Include ("*.zip") -ErrorAction SilentlyContinue | |
#$rarFiles = Get-ChildItem -Recurse -path $arInputFolder -Include ("*.rar") -ErrorAction SilentlyContinue #, "*.r[0-9]", "*.r[0-9][0-9]", "*.r[0-9][0-9][0-9]") | |
#$isoFiles = Get-ChildItem -Recurse -path $arInputFolder -Include ("*.iso") -ErrorAction SilentlyContinue | |
#$password = "bitdownload.ir" | |
# foreach ($zFile in $zFiles) | |
# { | |
# $outPutFolder = "$($zFile.DirectoryName)" | |
# Write-Host "arInputFolder=$($arInputFolder)" | |
# Write-Host "Directory=$((get-item $zFile).Directory.FullName)" | |
# $outPutSubFolder = "" | |
# # https://www.sqlhammer.com/compare-paths-with-powershell/ | |
# if ((Join-Path "$($arInputFolder)" '') -eq (Join-Path "$((get-item # $zFile).Directory.FullName)" '')) { | |
# $outPutSubFolder = "$($zFile.BaseName -replace '\.part\d*$')\" | |
# } | |
# #$outPutFolderExtended = $outPutFolder + "\" + $zFile.BaseName | |
# | |
# # Use regex to remove the ‘part#’ part. | |
# $outPutFolderExtended = "$($outPutFolder)\$($outPutSubFolder.subString(0, # [System.Math]::Min(50, $outPutSubFolder.Length)))" | |
# | |
# #Expand-Archive -Path "$($zFile.FullName)" -DestinationPath # $outPutFolderExtended | |
# | |
# foreach ($password in $passwords) | |
# { | |
# Write-Host $password | |
# if ($password) { | |
# &$SZexe "t" "$($zFile.FullName)" "-p$($password)" ; | |
# if (-Not $?) | |
# { | |
# Write-Host "$($password) is not the password." | |
# } else { | |
# Write-Host "$($password) is the password." | |
# # Call 7zip. Provide password as an argument. | |
# #&$SZexe x "$($zFile.FullName)" "-o$($outPutFolderExtended)" # -y "-p$($password)" ; | |
# $arguments=@("x", """$($zFile.FullName)""", """-o$# ($outPutFolderExtended)""", "-y", "-p$($password)"); | |
# $ex = start-process -NoNewWindow -FilePath """$SZexe""" # -ArgumentList $arguments -wait -PassThru; | |
# if( $ex.ExitCode -eq 0) | |
# { | |
# write-host "Extraction successful, deleting $($zFile.# FullName)" | |
# #rmdir -Path "$($zFile.FullName)" -Force | |
# Remove-Item -Force -LiteralPath "$($zFile.FullName)" | |
# } else { | |
# Write-Host "Extraction failed with $($ex.ExitCode) of $# ($zFile.FullName)" | |
# } | |
# if( $outPutSubFolder.Length -ge 0) { | |
# & $movelonedirs -inputFolder "$($outPutFolderExtended)" | |
# } | |
# break # password found | |
# } | |
# } else { | |
# #&$SZexe x "$($zFile.FullName)" "-o$($outPutFolderExtended)" -y ; | |
# #if (-Not $?) | |
# #{ | |
# # Write-Host "empty password string failed" | |
# #} else { | |
# # break # password found | |
# #} | |
# $arguments=@("x", """$($zFile.FullName)""", """-o$# ($outPutFolderExtended)""", "-y", "-pbitdownload.ir"); | |
# $ex = start-process -NoNewWindow -FilePath """$SZexe""" # -ArgumentList $arguments -wait -PassThru; | |
# if( $ex.ExitCode -eq 0) | |
# { | |
# write-host "Extraction successful, deleting $($zFile.FullName)# " | |
# #rmdir -Path "$($zFile.FullName)" -Force | |
# Remove-Item -Force -LiteralPath "$($zFile.FullName)" | |
# } else { | |
# Write-Host "empty password string failed" | |
# Write-Host "Extraction failed with $($ex.ExitCode) of $# ($zFile.FullName)" | |
# } | |
# if( $outPutSubFolder.Length -ge 0) { | |
# & $movelonedirs -inputFolder "$($outPutFolderExtended)" | |
# } | |
# break # password found | |
# } | |
# } | |
# } | |
# | |
# foreach ($isoFile in $isoFiles) | |
# { | |
# $outPutFolder = "$($isoFile.DirectoryName)" | |
# Write-Host "arInputFolder=$($arInputFolder)" | |
# Write-Host "Directory=$((get-item $isoFile).Directory.FullName)" | |
# $outPutSubFolder = "" | |
# # https://www.sqlhammer.com/compare-paths-with-powershell/ | |
# if ((Join-Path "$($arInputFolder)" '') -eq (Join-Path "$((get-item # $isoFile).Directory.FullName)" '')) { | |
# $outPutSubFolder = "$($isoFile.BaseName -replace '\.part\d*$')\" | |
# } | |
# #$outPutFolderExtended = $outPutFolder + "\" + $isoFile.BaseName | |
# | |
# # Use regex to remove the ‘part#’ part. | |
# $outPutFolderExtended = "$($outPutFolder)\$($outPutSubFolder.subString(0, # [System.Math]::Min(50, $outPutSubFolder.Length)))" | |
# | |
# #Expand-Archive -Path "$($isoFile.FullName)" -DestinationPath # $outPutFolderExtended | |
# | |
# foreach ($password in $passwords) | |
# { | |
# Write-Host $password | |
# if ($password) { | |
# &$SZexe "t" "$($isoFile.FullName)" "-p$($password)" ; | |
# #&$UnRAR "t" "-p$($password)" "$($isoFile.FullName)" ; | |
# if (-Not $?) | |
# { | |
# Write-Host "$($password) is not the password." | |
# } else { | |
# Write-Host "$($password) is the password." | |
# # Call 7zip. Provide password as an argument. | |
# #&$SZexe x -tiso "$($isoFile.FullName)" "-o$# ($outPutFolderExtended)" -y "-p$($password)" ; | |
# #&$UnRAR x -o- "$($isoFile.FullName)" $outPutFolderExtended -y # "-p$($password)" ; | |
# #&$SZexe x "$($isoFile.FullName)" "-o$($outPutFolderExtended)" # -y "-p$($password)" ; | |
# $arguments=@("x", """$($isoFile.FullName)""", """-o$# ($outPutFolderExtended)""", "-y", "-p$($password)"); | |
# $ex = start-process -NoNewWindow -FilePath """$SZexe""" # -ArgumentList $arguments -wait -PassThru; | |
# if( $ex.ExitCode -eq 0) | |
# { | |
# write-host "Extraction successful, deleting $($isoFile.# FullName)" | |
# #rmdir -Path "$($isoFile.FullName)" -Force | |
# Remove-Item -Force -LiteralPath "$($isoFile.FullName)" | |
# } else { | |
# Write-Host "Extraction failed with $($ex.ExitCode) of $# ($isoFile.FullName)" | |
# } | |
# if( $outPutSubFolder.Length -ge 0) { | |
# & $movelonedirs -inputFolder "$($outPutFolderExtended)" | |
# } | |
# break # password found | |
# } | |
# } else { | |
# #&$SZexe x "$($isoFile.FullName)" "-o$($outPutFolderExtended)" -y ; | |
# $arguments=@("x", """$($isoFile.FullName)""", """-o$# ($outPutFolderExtended)""", "-y", "-pbitdownload.ir"); | |
# $ex = start-process -NoNewWindow -FilePath """$SZexe""" # -ArgumentList $arguments -wait -PassThru; | |
# if( $ex.ExitCode -eq 0) | |
# { | |
# write-host "Extraction successful, deleting $($isoFile.FullName)# " | |
# #rmdir -Path "$($isoFile.FullName)" -Force | |
# Remove-Item -Force -LiteralPath "$($isoFile.FullName)" | |
# } else { | |
# Write-Host "Extraction failed with $($ex.ExitCode) of $# ($isoFile.FullName)" | |
# Write-Host "empty password string failed" | |
# } | |
# if( $outPutSubFolder.Length -ge 0) { | |
# & $movelonedirs -inputFolder "$($outPutFolderExtended)" | |
# } | |
# break # password found | |
# #&$SZexe x -tiso "$($isoFile.FullName)" "-o$($outPutFolderExtended)# " -y ; | |
# #&$UnRAR x -o- "$($isoFile.FullName)" $outPutFolderExtended -y "-p$# ($password)" ; | |
# #if (-Not $?) | |
# #{ | |
# # Write-Host "empty password string failed" | |
# #} else { | |
# # break | |
# #} | |
# } | |
# } | |
# } | |
# | |
# foreach ($rarFile in $rarFiles) | |
# { | |
# $outPutFolder = "$($rarFile.DirectoryName)" | |
# Write-Host "arInputFolder=$($arInputFolder)" | |
# Write-Host "Directory=$((get-item $rarFile).Directory.FullName)" | |
# $outPutSubFolder = "" | |
# # https://www.sqlhammer.com/compare-paths-with-powershell/ | |
# if ((Join-Path "$($arInputFolder)" '') -eq (Join-Path "$((get-item # $rarFile).Directory.FullName)" '')) { | |
# $outPutSubFolder = "$($rarFile.BaseName -replace '\.part\d*$')\" | |
# } | |
# #$outPutFolderExtended = $outPutFolder + "\" + $rarFile.BaseName | |
# | |
# # Use regex to remove the ‘part#’ part. | |
# $outPutFolderExtended = "$($outPutFolder)\$($outPutSubFolder.subString(0, # [System.Math]::Min(50, $outPutSubFolder.Length)))" | |
# | |
# foreach ($password in $passwords) | |
# { | |
# if ($password) { | |
# Write-Host $password | |
# #&$UnRAR "lb" $($rarFile.FullName) "-p$($password)" -y | |
# #&$UnRAR "t" "-p$($password)" "$($rarFile.FullName)" ; | |
# #if (-Not $?) | |
# #{ | |
# # Write-Host "$($password) is not the password." | |
# #} else { | |
# # Write-Host "$($password) is the password." | |
# # # UnRAR the files. -y responds Yes to any queries UnRAR may # #have. | |
# # # https://stackoverflow.com/a/49236517 | |
# # &$UnRAR x -o- "$($rarFile.FullName)" $outPutFolderExtended -y # #"-p$($password)" ; | |
# # #&$WinRar x -o- "$($rarFile.FullName)" $outPutFolderExtended # -y "-p$($password)" ; | |
# # break # password found | |
# #} | |
# | |
# #&$SZexe "t" "$($rarFile.FullName)" "-p$($password)" ; | |
# &$UnRAR "t" "-p$($password)" "$($rarFile.FullName)" ; | |
# if (-Not $?) | |
# { | |
# Write-Host "$($password) is not the password." | |
# } else { | |
# Write-Host "$($password) is the password." | |
# # Call 7zip. Provide password as an argument. | |
# #&$SZexe x -tiso "$($rarFile.FullName)" "-o$# ($outPutFolderExtended)" -y "-p$($password)" ; | |
# #&$UnRAR x -o- "$($rarFile.FullName)" $outPutFolderExtended -y # "-p$($password)" ; | |
# #&$SZexe x "$($rarFile.FullName)" "-o$($outPutFolderExtended)" # -y "-p$($password)" ; | |
# # https://www.winrar-france.fr/winrar_instructions_for_use/# source/html/HELPSwitches.htm | |
# #$arguments=@("x", "-o-", """$($rarFile.FullName)""", """$# ($outPutFolderExtended)""", "-y", "-p$($password)"); | |
# #$ex = start-process -NoNewWindow -FilePath """$UnRAR""" # -ArgumentList $arguments -wait -PassThru; | |
# $arguments=@("x", """$($rarFile.FullName)""", """-o$# ($outPutFolderExtended)""", "-y", "-p$($password)"); | |
# $ex = start-process -NoNewWindow -FilePath """$SZexe""" # -ArgumentList $arguments -wait -PassThru; | |
# if( $ex.ExitCode -eq 0) | |
# { | |
# write-host "Extraction successful, deleting $($rarFile.# FullName)" | |
# #rmdir -Path "$($rarFile.FullName)" -Force | |
# Remove-Item -Force -LiteralPath "$($rarFile.FullName)" | |
# } else { | |
# Write-Host "Extraction failed with $($ex.ExitCode) of $# ($rarFile.FullName)" | |
# } | |
# if( $outPutSubFolder.Length -ge 0) { | |
# & $movelonedirs -inputFolder "$($outPutFolderExtended)" | |
# } | |
# break # password found | |
# } | |
# } else { | |
# #&$UnRAR x -o- "$($rarFile.FullName)" $outPutFolderExtended -y ; | |
# #if (-Not $?) | |
# #{ | |
# # Write-Host "empty password string failed" | |
# #} else { | |
# # break # password found | |
# #} | |
# | |
# # https://www.winrar-france.fr/winrar_instructions_for_use/source/# html/HELPSwitches.htm | |
# #$arguments=@("x", "-o-", """$($rarFile.FullName)""", """$# ($outPutFolderExtended)""", "-y", "-pbitdownload.ir"); | |
# #$ex = start-process -NoNewWindow -FilePath """$UnRAR""" # -ArgumentList $arguments -wait -PassThru; | |
# $arguments=@("x", """$($rarFile.FullName)""", """-o$# ($outPutFolderExtended)""", "-y", "-pbitdownload.ir"); | |
# $ex = start-process -NoNewWindow -FilePath """$SZexe""" # -ArgumentList $arguments -wait -PassThru; | |
# if( $ex.ExitCode -eq 0) | |
# { | |
# write-host "Extraction successful, deleting $($rarFile.FullName)# " | |
# #rmdir -Path "$($rarFile.FullName)" -Force | |
# Remove-Item -Force -LiteralPath "$($rarFile.FullName)" | |
# } else { | |
# Write-Host "empty password string failed" | |
# Write-Host "Extraction failed with $($ex.ExitCode) of $# ($rarFile.FullName)" | |
# } | |
# if( $outPutSubFolder.Length -ge 0) { | |
# & $movelonedirs -inputFolder "$($outPutFolderExtended)" | |
# } | |
# break # password found | |
# } | |
# } | |
# | |
# # https://stackoverflow.com/a/33007614 | |
# # "%ProgramFiles%\WinRAR\UnRAR.exe" x -ad -c- -cfg- -inul -o+ -y "C:\Temp\*.# rar" "C:\Temp\Extracted\" | |
# | |
# # Call 7zip. Provide password as an argument. | |
# #&$SZexe x $rarFile "-o$($outPutFolderExtended)" -y "-p$($password)" ; | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git ls-files -z --others --exclude-standard | tr '\0' '\n' | head -n 50000 | tr '\n' '\0' | xargs -0 -L1 -I '$' git add '$' -v ; git commit -m "first commit" ; git push --all origin --no-verify
OR
git status --porcelain --untracked-files -z | tr '\0' '\n' | grep '??' | awk '{print substr($0, index($0, $2))}' | head -n 50000 | tr '\n' '\0' | xargs -0 -L1 -I '$' git add '$' -v ; git commit -m "first commit" ; git push --all origin --no-verify
readarray -d '' files_array < <(git status --porcelain --untracked-files -z) ; for f in "${files_array[@]}" ; do x=$(echo "$f" | grep '??' | awk '{print substr($0, index($0, $2))}' ) ; echo $x ; y=$(echo "$x" | tr '\n' '\0' | xargs -0 -L1 -I '$' git add '$' -v ) ; echo $y ; done
git ls-files -z --others --exclude-standard | tr '\n' '\0' | xargs -0 -L1 -I '$' git add '$' -v
git status --porcelain --untracked-files | head -n 50000 | grep '??' | awk '{print substr($0, index($0, $2))}' | xargs git add
https://stackoverflow.com/a/15762313
git add $(git ls-files --others --exclude-standard | head -n 50000) ; git commit -m "first commit" ; git push -u origin main
git ls-files --others --exclude-standard | sed "s/^/'/;s/$/'/" | head -n 50000 | xargs git add ; git commit -m "first commit" ; git push -u origin main
https://stackoverflow.com/questions/37394407/how-to-git-add-all-but-limit-it-to-maximum-100-at-a-time
infile.txt tail -n +"$X" | head -n "$((Y - X))"
https://unix.stackexchange.com/questions/47407/cat-line-x-to-line-y-on-a-huge-file