Results 1 to 2 of 2

Thread: converting powershell

  1. #1
    Arne25 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    1
    Reputation
    0

    converting powershell

    Hi guys,

    I have a problem. I need to convert this PowerShell program to vb.net or VbScript.
    But i can't find the solution..
    Could anyone help me with this?

    function Remove-EmptyFolders {
    [CmdletBinding()]
    param ()

    $delDirs = @()
    $dirs = Get-ChildItem -Recurse | Where-Object { ($_.PsIsContainer) }
    foreach ($dir in $dirs) {
    $l = 0
    $files = Get-ChildItem $dir.PSPath -Recurse | Where-Object { (!($_.PsIsContainer)) }
    foreach ($file in $files) {
    $l += $file.length
    } # end foreach $file
    if ($l -eq 0) {
    Write-Verbose "$($dir.pspath | split-path -noqualifier) has no files"
    $delDirs += $dir.PSPath
    } # end if
    else {Write-Verbose "$($dir.pspath | split-path -noqualifier) has $l bytes in files"}
    } # end foreach $dir

    Write-Host "The following empty directories will be removed."
    Write-Host "Press 'y' to continue, any other key to stop:"
    $delDirs | ForEach-Object { Split-Path $_ -NoQualifier }
    if ($host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").C haracter -eq 'y') {
    $delDirs | Remove-Item -Recurse -ErrorAction SilentlyContinue
    Write-Host "$($delDirs.count) directories deleted"
    } # end if
    } # end function

    greetings

  2. #2
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    308
    Have a look at these:

    DirectoryInfo Class (System.IO)

    My.Computer.FileSystem Object


    Alternately, since deleting empty folders most likely has been done by someone before, you could search Google for the term "vb.net remove empty folders".

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking