sl 'C:\Arquivos\Log'; dir *.log | % {& "${env:ProgramFiles}\7-Zip\7z.exe" a $_.BaseName $_.Name}
1. Enter the folder where you want to create your files or at least point to it:
# Entre na pasta:
Set-Location 'C:\Arquivos\Log' ...
# Ou aponte para ela:
pushd 'C:\Arquivos\Log'; dir *.log | ... ; popd
2. Use relative path to the 7zip
or, set a path for him:
# Use caminho relativo:
"${env:ProgramFiles}\7-Zip\7z.exe"
# Ou defina o caminho dele:
$7z=(Get-Item -r $env:ProgramFiles -Filter 7-Zip\7z.exe -Force -EA 0).fullname
3. dir C:\Arquivos\Log\*.log
and $_.BaseName
results in the creation of files in the current working folder where Powershell is or has been started:
# Funciona se o usuario atual tem permição de escrita na pasta atual de trabalho
dir C:\Arquivos\Log\*.log | ForEach-Object { & "C:\Program Files\7-Zip\7z.exe" a $_.BaseName $_.Name }
- Some issues suggesting the use of items 1 and 2:
Set-Location 'C:\Arquivos\Log'; dir *.log | ForEach-Object {& "${env:ProgramFiles}\7-Zip\7z.exe" a $_.BaseName $_.Name}
# ou...
sl 'C:\Arquivos\Log'; dir *.log | % {& "${env:ProgramFiles}\7-Zip\7z.exe" a $_.BaseName $_.Name}
pushd 'C:\Arquivos\Log' ; dir *.log | ForEach-Object {& "${env:ProgramFiles}\7-Zip\7z.exe" a $_.BaseName $_.Name} ; popd
# ou...
pushd 'C:\Arquivos\Log' ; dir *.log | ? {& "${env:ProgramFiles}\7-Zip\7z.exe" a $_.BaseName $_.Name} ; popd
$7z=(Get-ChildItem -r $env:ProgramFiles -Filter 7-Zip\7z.exe -Force -EA 0).fullname
Set-Location 'C:\Arquivos\Log'; ls *.log | ForEach-Object {& "$7z" a $_.BaseName $_.Name}
# Ou...
$7z=(ls -r $env:ProgramFiles -Filter 7-Zip\7z.exe -Force -EA 0).fullname
sl 'C:\Arquivos\Log'; ls *.log | ? {& "$7z" a $_.BaseName $_.Name}
Thanks Bruno, it worked the way I wanted it. Hug.
– Rodrigo Rios