Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.
When somebody PGP encrypts a file, the encrypted file is often given a different name than the original file, but the original filename is still stored along with the rest of the data in the encrypted file.
For example, you can start with a file called "my_data.txt" and PGP encrypt it, calling the resulting file, "encrypted_data.txt.pgp." So, as you can see, the encrypted file can be called anything you want.
The original filename will still be stored along with the rest of the data. So, when you PGP decrypt the file with the PGPDECRYPT command, the resulting decrypted file will have the original filename ("my_data.txt" in this case).
There may be cases where you do not want to use the original filename after decrypting a file.
This sample script shows how to specify the filename to use for the decrypted file. It looks for all the .pgp files in a directory and decrypts them, naming the decrypted file by removing the .pgp extension.
1 WORKINGDIR "C:\encrypted_files" 2 :loop 3 GETNEXTFILE "*.pgp" 4 IFERROR RETURN $ERROR_SUCCESS 5 SETREPLACE filename = %nextfile ".pgp" "" 6 PGPDECRYPT %nextfile filename 7 ;If decryption fails, exit 8 IFERROR RETURN 9 DELETE %nextfile 10 GOTO loop