How to check if URL is a file or directory

walden systems, powershell, url, directory, get-item
PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes. PowerShell commands let you manage computers from the command line. PowerShell providers let you access data stores, such as the registry and certificate store, as easily as you access the file system. PowerShell includes a rich expression parser and a fully developed scripting language.

You can use Microsoft's PowerShell to determine if a given URL is a directory or file. To start PowerShell, click on Start -> find and type in "PowerShell" ( without the quotes ). Windows PowerShell will show up. Right click on Windows PowerShell and click on Run as Administrator, this will bring up Windows PowerShell.

We will use the following PowerShell command :

Get-Item will load the file or directory object

System.IO.DirectoryInfo to determine if it is a directory or not.
Will return TRUE if it is a directory or FALSE if not.


First we load the URL to an object and then check the object's properties:

$item = Get-Item SOME_URL
$isDir = $item -is [System.IO.DirectoryInfo]
$isDir

The above code will return TRUE if the URL given is a directory