0 Pluspunkte 0 Minuspunkte

Ich habe ein Script

Get-ChildItem -Directory -Path "E:\" -Recurse -Depth 10 | foreach-object { 

    $p = $_.FullName -replace '\\', '\\' # escape
    $depth = ??
    write-host "processing entry $($c)"
    $query = "insert into folders (path, depth) values (""$($p)"", $($depth));"; 
    mysqlset -Query $query 
    $c++

}

Wie kann ich die Depth in einer Variable speichern?

von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

Dazu kannst du dir eine Funktion schreiben.

function Get-Depth {     
    param (         
        [string]$base,         
        [string]$path    
    )     
    $relativePath = $path.Substring($base.Length)     
    return ($relativePath.Split('\') | Where-Object { $_ -ne '' }).Count 
}

Aufrufen kannst du sie mit

Get-Depth -base "E:\" -path "E:\test"
von (396 Punkte)