Skip to content

Instantly share code, notes, and snippets.

@maxwellamaral
Last active July 6, 2024 14:48
Show Gist options
  • Save maxwellamaral/0204d6e833eb02bd6ba5f8824e6598e4 to your computer and use it in GitHub Desktop.
Save maxwellamaral/0204d6e833eb02bd6ba5f8824e6598e4 to your computer and use it in GitHub Desktop.
Alterar diretório no sistema Johnny Decimal no Powershell | Change directory on Johnny Decimal system on Powershell
function cdj {
param (
[string]$folderName
)
# Atualize com a pasta raiz dos seus documentos
$rootPath = "D:\Cloud\OneDrive"
# Lista de diretórios correspondentes ao padrão
$matchingDirs = Get-ChildItem -Path $rootPath -Directory -Recurse | Where-Object { $_.Name -like "*$folderName*" }
# Verifica se há correspondências
if ($matchingDirs.Count -eq 0) {
Write-Host "Nenhum diretório correspondente encontrado para '$folderName'."
return
}
# Se houver apenas uma correspondência, navegue até ela
if ($matchingDirs.Count -eq 1) {
Set-Location -Path $matchingDirs[0].FullName
} else {
# Se houver várias correspondências, liste-as
Write-Host "Múltiplos diretórios correspondentes encontrados para '$folderName':"
$matchingDirs | ForEach-Object { Write-Host $_.FullName }
}
}
@maxwellamaral
Copy link
Author

Simple script for PowerShell

function cdjd {
  param (
    [string]$folderName
  )

  # Atualize com a pasta raiz dos seus documentos
  $rootPath = "D:\Cloud\OneDrive"

  # Concatena $rootPath com $folderName usando o comando pushd
  pushd "$rootPath\*\*\$folderName*"

}

@maxwellamaral
Copy link
Author

To run Windows Explorer

function cdem {
    param (
        [string]$folderName
    )

    # Atualize com a pasta raiz dos seus documentos
    $rootPath = "D:\Cloud\OneDrive"

    # Lista de diretórios correspondentes ao padrão
    $matchingDirs = Get-ChildItem -Path $rootPath -Directory -Recurse | Where-Object { $_.Name -like "*$folderName*" }

    Write-Host "hello"

    # Verifica se há correspondências
    if ($matchingDirs.Count -eq 0) {
        Write-Host "Nenhum diretório correspondente encontrado para '$folderName'."
        return
    }

    # Se houver apenas uma correspondência, navegue até ela
    if ($matchingDirs.Count -eq 1) {
        Write-Host "$folderName"
        explorer.exe $matchingDirs[0].FullName
    }
    else {
        # Se houver várias correspondências, liste-as
        Write-Host "Múltiplos diretórios correspondentes encontrados para '$folderName':"
        $matchingDirs | ForEach-Object { Write-Host $_.FullName }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment