Hi there,
I am busy cleaning up our backdated files where we have zipped the files to save storage space.
I am trying to create the code to scan through my various folders and if there are files that have been unzipped then it zips it if the zipped file doesn't exists, otherwise if the files have been unzipped and the zipped ones exists, then it should delete the original file.
It would be *possible* to do this with SAS, but probably better to use some sort of shell script. If you're doing it with SAS, can you show the code you have tried, and describe where you're stuck? If you're looking for examples of how to zip files using SAS, I would try searching lexjansen.com for user group papers. This search string has plenty of hits: https://www.google.com/search?q=site%3Alexjansen.com+zip+-%22zipcode%22
More details are required to give details.
What types of files are these?
What type of "zip" files are you making?
If they are actually gzip files then it will be easier since a gzip file contains only one original file. But at an actual zip file is an archive file format that can contain multiple files. So figuring out whether a non zipped file exists in one of the existing zip archive files will be harder.
You will probably want to start be getting the list of files. You could use this macro: https://github.com/sasutils/macros/blob/master/dirtree.sas
Which can be used to build a dataset with the names size and dates for all files in one (or more) directory trees.
@Citrine10 wrote:
Hi there,
I am busy cleaning up our backdated files where we have zipped the files to save storage space.
I am trying to create the code to scan through my various folders and if there are files that have been unzipped then it zips it if the zipped file doesn't exists, otherwise if the files have been unzipped and the zipped ones exists, then it should delete the original file.
This sounds like a seriously dangerous potential cause of loss of data. So if there is one "Backup.zip" do you intend to delete every "backup.txt" "backup.xls" "backup.doc" "backup.bmp" "backup.png"?
I would say that if your process does not "unzip" and verify the contents match the file you are considering deleting that it is a flawed process. Without a comparison, there is no guarantee that the zipped file has the latest version is there?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.