Last active
October 3, 2025 11:07
-
-
Save geotheory/e53f4d6835036f0b8a0c795be062b18a to your computer and use it in GitHub Desktop.
valid-zip-archive.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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