Skip to content

Instantly share code, notes, and snippets.

@altbdoor
Last active March 4, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altbdoor/a9d0a1697e5cbb603b5eaef69ad8622c to your computer and use it in GitHub Desktop.
Save altbdoor/a9d0a1697e5cbb603b5eaef69ad8622c to your computer and use it in GitHub Desktop.
@echo off
set "sevenz_path=C:\Program Files\7-Zip\7z.exe"
set temp_file=%temp%\7zl_output.txt
set is_found_compressed_line=0
set is_found_file_line=0
set garbage_count=
"%sevenz_path%" l "%~1" > "%temp_file%"
for /f "tokens=* delims=," %%a in (%temp_file%) do call :process_file "%%a"
pause > nul
goto :eof
:process_file
set current_line=%1
set spaceless_line=%current_line: =-%
set spaceless_line=%spaceless_line:"=%
set sanitized_line=%current_line:"=_%
set nameless_string=%sanitized_line:Name_=%
:start_strip_right_name
if not "%nameless_string:~-1%" == " " goto :end_strip_right_name
set nameless_string=%nameless_string:~0,-1%
goto :start_strip_right_name
:end_strip_right_name
if "%sanitized_line:~-5%" == "Name_" (
if %is_found_compressed_line% equ 0 (
set is_found_compressed_line=1
call :strLen nameless_string garbage_count
)
)
set /a "new_garbage_count=%garbage_count%+2"
if "%spaceless_line:~0,10%" == "----------" (
if "%spaceless_line:~-10%" == "----------" (
set /a "is_found_file_line=%is_found_file_line%+1"
goto :eof
)
)
if %is_found_file_line% equ 1 (
if not "%sanitized_line:....A=%" == "%sanitized_line%" (
setlocal enableDelayedExpansion
echo !sanitized_line:~%new_garbage_count%,-1!
endlocal
)
)
goto :eof
rem http://stackoverflow.com/a/13924161
:strLen strVar [rtnVar]
setlocal disableDelayedExpansion
set len=0
if defined %~1 for /f "delims=:" %%N in (
'"(cmd /v:on /c echo(!%~1!&echo()|findstr /o ^^"'
) do set /a "len=%%N-3"
endlocal & if "%~2" neq "" (set %~2=%len%) else echo %len%
#!/bin/bash
if [[ -f "$1" ]]; then
zip_output=$(7z l "$1")
# cut off at the text Compressed
cutoff_len=$(grep -oP "^\s+Date.+?Compressed" <<< "$zip_output")
cutoff_len=${#cutoff_len}
# but cut is one-indexed
cutoff_len=$((cutoff_len+1))
# grep only files
# then cut by the cut off length
# then trim the leading space and unix-ify path
zip_output=$(echo "$zip_output" | grep "\.\.\.\.A" | cut -c "$cutoff_len-" | sed -e 's/^[[:space:]]*//' -e 's/\\/\//g')
echo "$zip_output"
else
echo "Zip path not found"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment