Python script to compress all pdf files in a directory on Windows 7
Question: Following the code sample
[here](http://stackoverflow.com/questions/27111760/script-to-compress-all-pdf-
files-in-a-directory), I have the code below that is supposed to compress
files in a directory using Ghostscript. The code compresses the files but then
when I open the files, I do not see any content at all. I only want the files
to be compressed. I don`t want the content to be erased.

    
    
    from __future__ import print_function
    import os
    import subprocess
    
    for root, dirs, files in os.walk("C:\comp"):
        for file in files:
            if file.endswith(".pdf"):
                filename = os.path.join(root, file)
                print (filename)
                arg1= '-sOutputFile=' + file
                p = subprocess.Popen(['C:/Program Files/gs/gs9.15/bin/gswin64c.exe',
                                      '-sDEVICE=pdfwrite', 
                                      '-dCompatibilityLevel=1.4', 
                                      '-dPDFSETTINGS=/screen', '-dNOPAUSE', 
                                      '-dBATCH', '-dQUIET', str(arg1), filename], 
                                     stdout=subprocess.PIPE)
                print (p.communicate())
    


Answer: I fixed the issue following @KenS suggestion of giving the output file a
different name and this worked.

    
    
    from __future__ import print_function
    import os
    import subprocess
    
    for root, dirs, files in os.walk("C:\comp"):
        for file in files:
            if file.endswith(".pdf"):
                filename = os.path.join(root, file)
                print (filename)
                arg1= '-sOutputFile=' + "c" +  file #added a c to the filename
                p = subprocess.Popen(['C:/Program Files/gs/gs9.15/bin/gswin64c.exe',
                                      '-sDEVICE=pdfwrite', 
                                      '-dCompatibilityLevel=1.4', 
                                      '-dPDFSETTINGS=/screen', '-dNOPAUSE', 
                                      '-dBATCH', '-dQUIET', str(arg1), filename], 
                                     stdout=subprocess.PIPE)
                print (p.communicate())

