Вы находитесь на странице: 1из 5

TOPIC

about_Path_Syntax

SHORT DESCRIPTION
Describes the full and relative path name forma
ts in Windows PowerShell.

LONG DESCRIPTION
All items in a data store accessible through a
Windows PowerShell provider
can be uniquely identified by their path names.
A path name is a
combination of the item name, the container and
subcontainers in which
the item is located, and the Windows PowerShell
drive through which the
containers are accessed.

In Windows PowerShell, path names are divided i


nto one of two types: fully
qualified and relative. A fully qualified path
name consists of all
elements that make up a path. The following syn
tax shows the elements in
a fully qualified path name:

[<provider>::]<drive>:[\<container>[\<subco
ntainer>...]]\<item>

The <provider> placeholder refers to the Window


s PowerShell provider
through which you access the data store. For ex
ample, the FileSystem
provider allows you to access the files and dir
ectories on your computer.
This element of the syntax is optional and is n
ever needed because the
drive names are unique across all providers.
The <drive> placeholder refers to the Windows P
owerShell drive that is
supported by a particular Windows PowerShell pr
ovider. In the case of the
FileSystem provider, the Windows PowerShell dri
ves 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 FileSy
stem provider creates the
same drives in Windows PowerShell.

After you have specified the drive, you must sp


ecify any containers and
subcontainers that contain the item. The contai
ners must be specified
in the hierarchical order in which they exist i
n the data store. In
other words, you must start with the parent con
tainer, then the child
container in that parent container, and so on.
In addition, each
container must be preceded by a backslash. (Not
e that Windows PowerShell
allows you to use forward slashes for compatibi
lity with other
powershells.)

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 t
he C:\Windows\System32
directory is as follows:

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

In some situations, you do not need to specify


a fully qualified path
name and can instead use a relative path name.
A relative path name is
based on the current working location. Windows
PowerShell allows you to
identify an item based on its location relative
to the current working
location. You can specify relative path names b
y using special characters.
The following table describes each of these cha
racters and provides
examples of relative path names and fully quali
fied path names. The
examples in the table are based on the current
working directory being
set to C:\Windows.

Symbol Description Relative path


Fully qualified path
------ -------------------------- -------------
--- --------------------
. Current working location .\System
c:\Windows\System
.. Parent of current working ..\Program Fi
les c:\Program Files
location
\ Drive root of current \Program File
s c:\Program Files
working location
[none] No special characters System
c:\Windows\System

When using a path name in a command, you enter


that name in the same
way whether you use a fully qualified path name
or a relative one. For
example, suppose that your current working dire
ctory is C:\Windows. The
following Get-ChildItem command retrieves all i
tems in the C:\Techdocs
directory:

Get-ChildItem \techdocs

The backslash indicates that the drive root of


the current working
location should be used. Because the working di
rectory is C:\Windows,
the drive root is the C: drive. Because the tec
hdocs directory is located
off the root, you need to specify only the back
slash.

You can achieve the same results by using the f


ollowing command:

Get-ChildItem c:\techdocs

Regardless of whether you use a fully qualified


path name or a relative
path name, a path name is important not only be
cause it locates an item
but also because it uniquely identifies the ite
m even if that item
shares the same name as another item in a diffe
rent container.
For instance, suppose that you have two files t
hat are each named
Results.txt. The first file is in a directory n
amed C:\Techdocs\Jan,
and the second file is in a directory named C:\
Techdocs\Feb. The path
name for the first file (C:\Techdocs\Jan\Result
s.txt) and the path name
for the second file (C:\Techdocs\Feb\Results.tx
t) allow you to clearly
distinguish between the two files.

SEE ALSO
about_Locations

Вам также может понравиться