Oliver Borchert Oliver Borchert - 21 days ago 4x
Git Question

Windows Powershell equivalent of bash command

I'm trying to use git for Excel files. However, I have to unzip and zip the components together later to accomplish this. For this task I wrote a script which turned out to be easy on MacOS. Since I'm not using Windows myself, I don't know how to fully convert this script into Windows Power Shell commands properly. How can I execute the following bash command in Windows Power Shell?

find . -type f | xargs zip ../../MyExcelFile.xlsm

What I haven't tried out yet, is unzipping the file. In bash there is the following command:

unzip MyExcelFile.xlsm -d XML/MyExcelFileXML

Does it do the same in Windows Power Shell or how can I convert that?

Thanks for your help!


PowerShell doesn't have an exact equivalent to find. Normally you'd use Get-ChildItem and emulate the filter parameters of the find command with a Where-Object filter. In your case for instance like this:

Get-ChildItem . -Recurse | Where-Object { -not $_.PSIsContainer }

In PowerShell v3 or newer you could also do this particular statement with Get-ChildItem alone:

Get-ChildItem . -Recurse -File

Instead of xargs you'd normally use a ForEach-Object loop (if the downstream command can't read from the pipeline by itself).

There is no builtin zip or unzip command in Windows, though (at least not prior to PowerShell v5). You can either use the Windows ports of those commands available from GnuWin32, replace the commands with another external command like 7-zip, or write functions to utilize the API methods for handling zip archives (see for instance this question).