Skip to content

Instantly share code, notes, and snippets.

@geotheory
Last active October 3, 2025 11:07
Show Gist options
  • Save geotheory/e53f4d6835036f0b8a0c795be062b18a to your computer and use it in GitHub Desktop.
Save geotheory/e53f4d6835036f0b8a0c795be062b18a to your computer and use it in GitHub Desktop.
valid-zip-archive.R
# test if a file is a valid zip archive
# can be used to distinguish old MS documents from current xml formats (e.g. doc from docx)
valid_zip = function(filepath, zippath = "/usr/bin/zip"){
zip_status = suppressWarnings(system(paste0(zippath, ' -T "', filepath, '"'), intern = TRUE))
return(length(stringr::str_subset(zip_status, 'OK$')) > 0)
}
# e.g.
# valid_zip("file.doc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment