Working with Files and Folders

Harry · 13 Sep 2026 · 1 views

Navigate and List

Set-Location C:work          # cd
Get-Location                  # pwd
Get-ChildItem -Recurse -Filter *.ps1

Create and Remove

New-Item -ItemType Directory -Path C:ackups -Force
New-Item -ItemType File -Path C:ackups
otes.txt
Remove-Item C:old -Recurse -Force

Read and Write

Get-Content C:worklog.txt -Tail 20
Set-Content C:out.txt 'first line'
Add-Content C:out.txt 'second line'

Copy and Move with Filters

Copy-Item C:a*.txt D:
Move-Item C:a D:archived
Get-ChildItem -Filter *.log | Where-Object { $_.Length -gt 1MB } | Remove-Item

Key Points

  • Get/Set/New/Remove-Item cover the full FS cycle.
  • Get-Content -Tail reads log tails fast.
  • Path-independent filtering composes with the pipeline.
  • New-Item -Force creates parents idempotently.
Share this post:

Comments (0)

Please login or register to comment.