Frage

I'm working on a powershell script erase certain files from a folder, and move the rest into predefined subfolders.

My structure looks like this

Main
    (Contains a bunch of pdb and dll files)
    -- _publish
        --Website
            (Contains a web.config, two other .config files and a global.asax file)
            -- bin
                (Contains a pdb and dll file)
            -- JS
            -- Pages
            -- Resources

I want to remove all pdb, config and asax files from the entire file structure before I start moving them. To which I use:

$pdbfiles = Get-ChildItem "$executingScriptDirectory\*.pdb" -recurse

foreach ($file in $pdbfiles) {
    Remove-Item $file
}

And so on for all filetypes I need removed. It works great except for a pdb file located in the bin folder of the website. And for the ASAX file in the website folder. For some reason they get ignored by the Get-ChildItem recurse search.

Is this caused by the depth of the items within the resursive structure? Or is it something else? How can I fix it, so it removes ALL files as specified.

EDIT: I have tried adding -force - But it changed nothing

ANSWER: The following worked:

$include = @("*.asax","*.pdb","*.config")
$removefiles = Get-ChildItem "$executingScriptDirectory\*" -recurse -force -include $include 

foreach ($file in $removefiles) {
    if ($file.Name -ne "Web.config") {
        Remove-Item $file
    }
}
War es hilfreich?

Lösung

Get-ChildItem -path <yourpath> -recurse -Include *.pdb

Andere Tipps

You can also use the pipe for remove:

Get-ChildItem -path <yourpath> -recurse -Include *.pdb | rm
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top