Skip to content

Instantly share code, notes, and snippets.

@rytsikau
Created July 16, 2020 06:25
Show Gist options
  • Save rytsikau/62df29583710cf3aaf6e1be8b005a571 to your computer and use it in GitHub Desktop.
Save rytsikau/62df29583710cf3aaf6e1be8b005a571 to your computer and use it in GitHub Desktop.
Listing files contained inside zip archives of a specified folder
#------------------------------------------------------------------------------
# Listing files contained inside zip archives of a specified folder
#------------------------------------------------------------------------------
#<#----------------------------------------------------------------------------
function ListFilesInZips ([string]$inputFolder)
{
add-type -assembly System.IO.Compression.FileSystem
foreach ($zipFile in (get-childitem $inputFolder -filter '*.zip'))
{
$zipContent = [IO.Compression.ZipFile]::OpenRead($zipFile.FullName)
$list += $zipContent.Entries.FullName | ?{ $_ -notmatch '\/$' } `
| %{ "$zipFile`:$_" }
$zipContent.Dispose()
}
return $list
}
#----------------------------------------------------------------------------#>
ListFilesInZips "c:\folderWithZips" | out-file "list.txt"
#------------------------------------------------------------------------------
# If zip archive(s) contain file names with non-latin characters,
# use function "ConvertTo-Encoding", which can be found here:
# https://xaegr.wordpress.com/2007/01/24/decoder
# For example:
# ListFilesInZips "c:\folderWithZips" | ConvertTo-Encoding cp866 windows-1251 `
# | out-file "list.txt"
#------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment