Searches all JavaScript files for classes that begin with Test
, excluding node_modules
dir:
gci -Recurse -Include *.js | ?{ $_.FullName -inotmatch 'node_modules' } | Select-String '\bclass\s+Test'
Replaces any licenses within package.json
files with MIT
(original files will be overwritten):
gci -Recurse -Filter package.json | Select-String '"license": ".+?"' -List | %{
((gc $_.Path -Raw -Encoding utf8) -replace '"license": ".+?"', '"license": "MIT"') | Out-File $_.Path -NoNewline -Encoding utf8 }
Another example of traversing:
gci -Recurse -Include *.py | %{
((gc $_.FullName -Raw -Encoding utf8) -replace 'assertNotEqual', 'assert_not_equals') | Out-File $_.FullName -NoNewline -Encoding utf8 }
Remarks:
- The
-List
option will group multiple matches within one file into single result. - The
-Raw
option will read entire file contents as one string. - The
-NoNewline
option will not add new line symbols to the end of the file.
Recursively scans and removes specified directories (build
and node_modules
):
gci -Recurse -Include build, node_modules -Directory | rmdir -Recurse -Force
Expand-Archive "$env:USERPROFILE\Downloads\ninja-win.zip" "$env:LOCALAPPDATA\Programs\ninja"
UTF16LE
illformed file fix (removes BOM
, zero bytes and CR
-only line breaks):
$CR = [byte][char]"`r"
$NL = [byte][char]"`n"
$bytes = [io.file]::ReadAllBytes('resource.h')
$bytes_fixed = [collections.generic.list[byte]]::new()
for ($i = 2; $i -lt $bytes_in.Length; $i++) {
$byte = $bytes[$i]
if ($byte -ne 0) {
if (($byte -eq $CR) -and ($bytes[$i + 1] -ne $NL)) {
continue
}
$bytes_fixed.Add($byte)
}
}
[io.file]::WriteAllBytes('resource_fixed.h', $bytes_fixed)
Open VS Code
, press Ctrl+Shift+P
, type Open Settings (JSON)
.
{
"powershell.integratedConsole.showOnStartup": false
}
{
"terminal.integrated.shell.windows": "C:/Program Files/PowerShell/7/pwsh.exe"
}
{
"[powershell]": {
"editor.codeLens": false
}
}