Skip to content

Commit

Permalink
Update slash character description
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler committed Sep 19, 2023
1 parent c4fdb06 commit f85eb3c
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 215 deletions.
65 changes: 32 additions & 33 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Locations.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes how to access items from the working location in PowerShell.
Locale: en-US
ms.date: 03/15/2021
ms.date: 09/19/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_locations?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Locations
Expand All @@ -10,45 +10,44 @@ title: about Locations
# about_Locations

## Short description

Describes how to access items from the working location in PowerShell.

## Long description

The current working location is the default location to which commands point.
In other words, this is the location that PowerShell uses if you do not supply
an explicit path to the item or location that is affected by the command.
In other words, this is the location that PowerShell uses if you don't supply
an explicit path to the item or location that's affected by the command.

> [!NOTE]
> PowerShell supports multiple runspaces per process. Each runspace has its own
> _current directory_. This is not the same as the current directory of the
> process: `[System.Environment]::CurrentDirectory`.
> _current directory_. This isn't the same as the current directory of the
> PowerShell process: `[System.Environment]::CurrentDirectory`.
In most cases, the current working location is a drive accessed through the
PowerShell FileSystem provider and, in some cases, a directory on that drive.
For example, you might set your current working location to the following
location:

```powershell
C:\Program Files\Windows PowerShell
Set-Location C:\Program Files\Windows PowerShell
```

As a result, all commands are processed from this location unless another path
is explicitly provided.

PowerShell maintains the current working location for each drive even when the
drive is not the current drive. This allows you to access items from the
drive isn't the current drive. This allows you to access items from the
current working location by referring only to the drive of another location.
For example, suppose that your current working location is `C:\Windows`. Now,
suppose you use the following command to change your current working location
to the HKLM: drive:
to the `HKLM:` drive:

```powershell
Set-Location HKLM:
```

Although your current location is now the registry drive, you can still access
items in the `C:\Windows` directory simply by using the C: drive, as shown in
the following example:
items in the `C:\Windows` directory using the `C:` drive, as shown in the
following example:

```powershell
Get-ChildItem C:
Expand All @@ -62,34 +61,34 @@ would be the same if you ran the following command:
Get-ChildItem C:\Windows
```

In PowerShell, you can use the Get-Location command to determine the current
working location, and you can use the Set-Location command to set the current
In PowerShell, you can use the `Get-Location` command to determine the current
working location, and you can use the `Set-Location` command to set the current
working location. For example, the following command sets the current working
location to the Windows directory of the C: drive:
location to the `Windows` directory of the `C:` drive:

```powershell
Set-Location c:\windows
Set-Location C:\Windows
```

After you set the current working location, you can still access items from
other drives simply by including the drive name (followed by a colon) in the
command, as shown in the following example:
other drives by including the drive name (followed by a colon) in the command,
as shown in the following example:

```powershell
Get-ChildItem HKLM:\software
```

The example command retrieves a list of items in the Software container of the
HKEY Local Machine hive in the registry.
`HKEY_LOCAL_MACHINE` hive in the registry.

PowerShell also allows you to use special characters to represent the current
working location and its parent location. To represent the current working
location, use a single period. To represent the parent of the current working
location, use two periods. For example, the following specifies the System
location, use two periods. For example, the following specifies the `System`
subdirectory in the current working location:

```powershell
Get-ChildItem .\system
Get-ChildItem .\System
```

If the current working location is `C:\Windows`, this command returns a list of
Expand All @@ -98,32 +97,32 @@ parent directory of the current working directory is used, as shown in the
following example:

```powershell
Get-ChildItem ..\"program files"
Get-ChildItem ..\"Program Files"
```

In this case, PowerShell treats the two periods as the C: drive, so the
command retrieves all the items in the `C:\Program Files` directory.

A path beginning with a slash identifies a path from the root of the current
drive. For example, if your current working location is
`C:\Program Files\PowerShell`, the root of your drive is C. Therefore, the
A path beginning with a backslash (`\`) identifies a path from the root of the
current drive. For example, if your current working location is
`C:\Program Files\PowerShell`, the root of your drive is `C:\`. Therefore, the
following command lists all items in the `C:\Windows` directory:

```powershell
Get-ChildItem \windows
Get-ChildItem \Windows
```

If you do not specify a path beginning with a drive name, slash, or period
when supplying the name of a container or item, the container or item is
assumed to be located in the current working location. For example, if your
current working location is `C:\Windows`, the following command returns all the
items in the `C:\Windows\System` directory:
If you don't specify a path beginning with a drive name, backslash (`\`), or
period (`.`) when supplying the name of a container or item, the container or
item is assumed to be located in the current working location. For example, if
your current working location is `C:\Windows`, the following command returns
all the items in the `C:\Windows\System` directory:

```powershell
Get-ChildItem system
Get-ChildItem System
```

If you specify a file name rather than a directory name, PowerShell returns
If you specify a filename rather than a directory name, PowerShell returns
details about that file (assuming that file is located in the current working
location).

Expand Down
50 changes: 30 additions & 20 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Path_Syntax.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the full and relative path formats in PowerShell.
Locale: en-US
ms.date: 08/29/2022
ms.date: 09/16/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_path_syntax?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Path Syntax
Expand All @@ -18,10 +18,9 @@ uniquely identified by their path names. A path is a combination of the
item name, the container and subcontainers in which the item is located, and
the PowerShell drive through which the containers are accessed.

In PowerShell, path names are divided into one of two types: fully qualified
and relative. A fully qualified path consists of all elements that make
up a path. The following syntax shows the elements in a fully qualified path
name:
In PowerShell, pathnames can be one of two types: _fully qualified_ and
_relative_. A fully qualified path consists of all elements that make up a
path. The following syntax shows the elements in a fully qualified path name:

```Syntax
[<provider>::]<drive>:[\<container>[\<subcontainer>...]]\<item>
Expand All @@ -33,32 +32,38 @@ access the files and directories on your computer. This element of the syntax
is optional and is never needed because the drive names are unique across all
providers.

The `<drive>` placeholder refers to the PowerShell drive that's supported by
a particular PowerShell provider. In the case of the FileSystem provider, the
PowerShell drives map to the Windows drives that are configured on your
system. For example, if your system includes an A: drive and a `C:` drive, the
The `<drive>` placeholder refers to the PowerShell drive that's supported by a
particular PowerShell provider. In the case of the FileSystem provider, the
PowerShell drives map to the Windows drives that are configured on your system.
For example, if your system includes an `A:` drive and a `C:` drive, the
FileSystem provider creates the same drives in PowerShell.

After you have specified the drive, you must specify any containers and
subcontainers that contain the item. The containers must be specified in the
hierarchical order in which they exist in the data store. In other words, you
must start with the parent container, then the child container in that parent
container, and so on. In addition, each container must be preceded by a
backslash. (Note that PowerShell allows you to use forward slashes for
compatibility with other PowerShells.)
container, repeating the pattern for each child container. In addition, each
container must be preceded by a backslash.

> [!NOTE]
> PowerShell allows you to use backslash or forward slash for compatibility
> with PowerShell on other platforms. This works for PowerShell commands, but
> may not work when used with native applications that only expect the native
> directory separator. Use `[System.IO.Path]::DirectorySeparatorChar` to find
> the character used for your platform.
After the container and subcontainers have been specified, you must provide
the item name, preceded by a backslash. For example, the fully qualified path
name for the Shell.dll file in the `C:\Windows\System32` directory is as
name for the `Shell.dll` file in the `C:\Windows\System32` directory is as
follows:

```powershell
C:\Windows\System32\Shell.dll
```

In this case, the drive through which the containers are accessed is the C:
drive, the top-level container is Windows, the subcontainer is System32
(located within the Windows container), and the item is Shell.dll.
In this case, the drive through which the containers are accessed is the `C:`
drive, the top-level container is `Windows`, the subcontainer is `System32`,
and the item is `Shell.dll`.

In some situations, you don't need to specify a fully qualified path and can
instead use a relative path. PowerShell allows you to identify an item based on
Expand Down Expand Up @@ -98,10 +103,10 @@ You get the same results using the fully qualified path:
Get-ChildItem C:\TechDocs
```

Regardless of whether you use a fully qualified path or a relative path
name, a path is important not only because it locates an item but also
because it uniquely identifies the item even if that item shares the same name
as another item in a different container.
Regardless of whether you use a fully qualified path or a relative path name, a
path is important not only because it locates an item but also because it
uniquely identifies the item even if that item shares the same name as another
item in a different container.

For instance, suppose that you have two files that are each named
`Results.txt`. The first file is in a directory named `C:\TechDocs\Jan`, and
Expand All @@ -113,3 +118,8 @@ two files.
## See also

- [about_Locations](about_Locations.md)
- [Convert-Path](xref:Microsoft.PowerShell.Management.Convert-Path)
- [Join-Path](xref:Microsoft.PowerShell.Management.Join-Path)
- [Resolve-Path](xref:Microsoft.PowerShell.Management.Resolve-Path)
- [Split-Path](xref:Microsoft.PowerShell.Management.Split-Path)
- [Test-Path](xref:Microsoft.PowerShell.Management.Test-Path)
Loading

0 comments on commit f85eb3c

Please sign in to comment.