When testing commands that work with the filesystem, Pester provides TestDrive. TestDrive is a temporary folder created in the current user's temporary directory.
The folder is created when Describe runs, and is destroyed afterwards.
Using TestDrive simplifies the setup process for the Remove-StaleFile function; for example, BeforeAll might become the following:
BeforeAll { $extensions = '.txt', '.log', '.doc' Push-Location 'TestDrive:' }
AfterAll becomes the following:
AfterAll { Pop-Location }
In the event that a command cannot work with the TestDrive label, as is the case with .NET types and methods, as well as non-PowerShell commands, the full path can be discovered by using Get-Item. This can be executed anywhere inside of a Describe block:
(Get-Item 'TestDrive:').FullName