Ankit Ankit - 2 months ago 12
C# Question

Extract All gz files inside a folder in C#

I am working on a application and need to extract the gz files inside a folder.

what I need is a c# script that can loop all gz files in a given folder and extract them into the same folder.

I know there are some libraries for this, But I could not able to get them work for gz, I got them working for zip though.

Or if there are any other solution for the same i.e if batch script can be created that can use WinRar command line utility to achieve the same. I don't know just an Idea if possible.

Note: I think I have to drop that second option- WinRar command is able to handle only RAR files.

Thanks

Answer

I got it solved. Thanks MichelZ for showing the way to go. I got the 7-zip command line version to done the trick for me.

@REM ------- BEGIN demo.cmd ----------------
@setlocal
@echo off
set path="C:\Program Files\7-Zip\";%path%
for /F %%i in ('dir /s/b *.gz') do call :do_extract "%%i"
for /F %%i in ('dir /s/b *.zip') do call :do_extract "%%i"
goto :eof

:do_extract
pushd %~dp1
7z e %1 -y
popd
REM ------- END demo.cmd ------------------
Comments