0% found this document useful (0 votes)
13 views3 pages

2 FilesAndDirectoriesManageInWindows en

Uploaded by

mnj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

2 FilesAndDirectoriesManageInWindows en

Uploaded by

mnj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FILE AND DIRECTORIES MANAGEMENT IN WINDOWS

Files and Directories


The organization and operation of directories and files in Windows is
equivalent to that of Linux. Therefore, the concepts of paths, .
directory and .. directory are equivalent.
When we talk about absolute paths, we have to notice the difference
between the root directory in Linux and in Windows.

Traverse directories.........................................1
How to manage an item in PS (file or directory)..............1
Text files content...........................................2
Compress and decompress items................................3

Traverse directories
When we want to refer to directories in PS, we will use the word
Location.
• Get-Location: to know the working directory. If we want to query
a different storage volume, we have to use the parameter -
PSDrive and the corresponding letter.
Get-Location -PSDrive C
• Set-Location path: to change the working directory
Set-Location C:\Users

How to manage an item in PS (file or directory)


PS generalizes the files and directory treatment with the word Item.
Remember that in Linux everything is a file.
• New-Item is the cmdlet to generate a new item and we will use
parameters in order to create a file or a directory.
New-Item -Path .\Desktop -Name directoryPS -ItemType directoryPS
New-Item .\file.txt -Value “Hello in the file”

1
The first one creates a directory and the second one creates a file
with the content “Hello in the file”. In addition, the second one
does not use optional parameter names. The value parameter is also
optional.

• Rename-Item path\name newpath\newname: to rename an Item. We are


omitting the -Newname parameter. We can use the optional -Force
parameter also.
• Copy-Item directory -Destination newpath -Recurse -Force: to
copy an item (file or directory) to a new path. We can use the
optional parameters recurse in order to copy subfolders,
subsubfolders and so on; and the force in case we find items
with special attributes like hidden or “only read”.
• Move-Item file -Destination newpath -Force: to move an item
(file or directory) to a new location.
• Get-ChildItem [path]: to list the content of a directory. Is the
equivalent to ls Linux command.
This cmdlet can be executed with the -Include parameter that
specify a pattern for the item names we want to recover. And the
-Exclude parameter that specify the pattern of the item names we
want to exclude. Both can be used with wildcards.
• Remove-Item path: to delete an item.
It also accepts the parameters: -Include, -Exclude an -Recurse.

Text files content


We can change the file content with the word Content.
• Get-Content path: to recover the text of a file.
• Set-Content file -Value “New text”: to change the file content.
• Add-Content file -Value “New text added”: to append new text to
the end of the file.
• Clear-Content file: to delete the content of a file.

2
Compress and decompress items
This cmdlets provide us of a way to join in a file several files and
directories. The size of the generated file will be smaller than the
sum of the items compressed.
Compress-Archive file1, dir2, file2 -DestinationPath file.zip -
CompresionLevel Optimal
Expand-Archive -Path file.zip -DestinationPath directory

References:
Based on Rafael López García notes.

You might also like