r/PowerShell • u/zaphodikus • Aug 11 '26
Question unzip file from a dos batch, but need absolute DOS paths
Seems a lot of effort and I feel I might be in a rabbit hole. But I'm a bit confused by the enclosing braces and escapes. I just want to unzip a file on windows.
powershell.exe -nologo -noprofile -command "& { $shell = New-Object -COM Shell.Application; $target = $shell.NameSpace(`.\temp`); $zip = $shell.NameSpace( '.\ethernetspeed.zip'); $target.CopyHere($zip.Items(), 16); }"
Which obvs does not work because the library wants absolute paths.
If I hard code the paths (as below) I have joy, but I don't want to hard-code
powershell.exe -nologo -noprofile -command "& { $shell = New-Object -COM Shell.Application; $target = $shell.NameSpace(`C:\temp`); $zip = $shell.NameSpace( 'C:\ethernetspeed.zip'); $target.CopyHere($zip.Items(), 16); }"
I'm a bit clueless as to how to prefix the paths with %~0dp and I last wrote powershells about 3 years ago. I'm also as usual struggling to get the markdown to markdown.
0
Upvotes
28
u/pigers1986 Aug 11 '26
Expand-Archive -Path 'C:\ethernetspeed.zip' -DestinationPath 'C:\temp' -Forcethis is powershell reddit ffs
4
u/odwulf Aug 11 '26
%~dp0 and the like is about your batch file location, not the current path. The current path is available with %cd%.
2
u/jasonvelocity Aug 11 '26
Please don't create new folders on the root of the driver. Windows has many named temp folders for this purpose.
1
u/BlackV Aug 11 '26
p.s. formatting the 3 backtick code fence does not work on old.reddit, 4 spaces works everywhere
it'll format it properly OR
Inline code block using backticks
`Single code line`inside normal textSee here for more detail
Thanks
1
u/gschizas Aug 13 '26
There's no DOS in 2026. The last time anything DOS was relevant, was more than 25 years ago.
Command Prompt is not DOS.
2
u/JeiceSpade Aug 11 '26
If it's a script instead of a command, you can use $PSScriptRoot
"$PSScriptRoot\ethernetspeed.zip" "$PSScriptRoot\temp"
2
u/420GB Aug 11 '26
Just use
No need for powershell. The destination path must already exist (mkdir), tar will fail otherwise.
1
u/Key-Confection-8257 Aug 18 '26
Hola yo tengo un script para descomprimir varios zip y consolidar todos en 2 archivos mi script completo y un demo de como funciona la tengo en la siguiente url https://www.programacionparatodos.com/2026/08/como-unir-archivos-csv-zip-powershell.html
9
u/[deleted] Aug 11 '26
[removed] — view removed comment