PowerShell / Community-Blog

Submissions for posts to the PowerShell Community Blog -https://devblogs.microsoft.com/powershell-community
MIT License
108 stars 47 forks source link

Update request - How can I determine if a folder exists? #15

Closed doctordns closed 3 years ago

doctordns commented 3 years ago

Request that this post from the older Scripting guys blog be updated and added.

Summary of the update request

termdew commented 3 years ago

Can this snippet be used as a solution? 🤔

"Test script if folder exists"
$path = Read-Host -Prompt 'Please enter a path '
if (Test-Path $path) {
    "Path exists!"
} else {
    "Path doesn't exist."
}
doctordns commented 3 years ago

That would indeed be a solution. Works in Windows PowerShell too. I'd rewrite this slightly for the blog:

$Folder = 'C:\Windows'
"Test to see if folder [$Folder]  exists"
if (Test-Path -Path $Folder) {
    "Path exists!"
} else {
    "Path doesn't exist."
}

All you have to do now is to write the article?

termdew commented 3 years ago

can be closed, as the blog post is released.

doctordns commented 3 years ago

resolved by #36 - closing this issue.