I have a script right now that looks for all files certain day old and certain file extension and it deletes all of the files. This works fine and it counts fine
Then I have to delete all folders that correspond to being empty and that includes all sub folders too. I also have to output this into a file and display each file deleted. The output would show 30 folders deleted but actually 48 were really deleted.
Now my question is i am trying to do a count of all the folders deleted. I have this script but it just counts the deepest folders not all the ones deleted. Here is the part of the script i can not get to count
Nested folders with no files in them... and others with files. The folders deleted were ONLY the deepest folder... I assume this would be due to parent folders *not* being empty... they contain other folders. In my case, the count was also correct
not sure if you tested this at all but i get an error of
The term 'prune-directory' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is co
rrect and try again.
At line:1 char:16
+ prune-directory <<<< c:\users\paul.healey\temp
+ CategoryInfo : ObjectNotFound: (prune-directory:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
daveTechSearch
prune-directory is actually a function that the author of the post wrote (see the article).
I am guessing that powershell is removing items from top level (rather than bottom up).. resulting in the skewed results... that is... all empty folders deleted, but the count does not add up for empty folders.
If I run this on my test folder:
$TargetFolder = "C:\folders\"
Open in new window