powershell command (cp, list, rename, find, count)

Photo by Elsa Noblet on Unsplash

powershell command (cp, list, rename, find, count)

Windows/power-shell-basic

·

1 min read

  • outline

basic command for Windows Power Shell

  • example

List of files ending with txt
Get-ChildItem *txt

Save list of files ending with wav to wavlist.txt

Get-ChildItem -filter *wav > wavlist.txt

Change file name

Change file name ending with txt to file name ending with log
Get-ChildItem *txt | Rename-Item -NewName { $_.Name -Replace 'txt', 'wav'}

count files ending with json
(Get-ChildItem -filter *json | Measure-Object).Count

Number of files in current folder
(Get-ChildItem -Recurse -File | Measure-Object).Count

Number of files ending with .mp3
Get-ChildItem "." -Filter *.mp3 -Recurse | Measure-Object

Removing files ending with .ogg
Get-ChildItem "." -Filter *.ogg -Recurse | Remove-Item

Removing files ending with .ogg with force option
Get-ChildItem "." -Filter *.ogg -Recurse | Remove-Item -force

  • reference

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/?view=powershell-7.3&viewFallbackFrom=powershell-7.1