>> Scan directory for ".z" files, decompress them all, compress the files as they get analysed one by one.
Are you modifying the data ? If not, you can leave out the compression step. Just simply decompress the stream, and process it.
>> Now I'm looking for a way for it to compress and decompress without me having to tell what the destination file will be.
If you want to save it to a file, you'll still need to somehow come up with a filename. What filename do you want to use ? You could use the filename of the source file, and change the extension eg., or add a suffix, or ...
Alternatively, you could use an automatically generated temporary filename using tmpnam (
http://www.cplusplus.com/reference/clibrary/cstdio/tmpnam/) eg.