I can run dos2unix
on one file in PowerShell:
dos2unix ./assets/style.css
How to do this for all CSS files under ./assets/
and its subdirectories?
I can run dos2unix
on one file in PowerShell:
dos2unix ./assets/style.css
How to do this for all CSS files under ./assets/
and its subdirectories?
'.\assets' | Get-ChildItem -Recurse -File -Filter '*.css' | ForEach-Object {
dos2unix $_.FullName
}
Get-ChildItem
is like dir
or ls
(in powershell the latter 2 are aliases for that cmdlet).
-File
means return only files.
-Recurse
means recurse child directories.
-Filter
allows us to get only the file pattern desired.
Then we pipe that into ForEach-Object
to execute a script block for each file returned and in there, we just execute the dos2unix command.
FullName
is the property of the file object that contains the full path to the file.
$path | Join-Path -Child Path 'whatever'
when possible. I just like the pipeline! Good point about -File
. –
Scarce Out-Null
. I'm on mobile now so I can't post a proper example. –
Scarce © 2022 - 2024 — McMap. All rights reserved.
'.\assets'
. Why not justGet-ChildItem Assets -Recure -Filter *.css | Foreach {dos2unix $_.FullName}
? Note that you don't need to quote*.css
. Also, use of -File will only work on PowerShell v3 and later. – Conceal