Encrypt all the files in a specified directory in Windows
Here is a Python script that you can use to encrypt all the files in a specified directory in Windows:
import os
import pyAesCrypt
# Set the directory that you want to encrypt
directory = "C:\\example\\"
# Set the password for the encryption
password = "password123"
# Set the buffer size
bufferSize = 64 * 1024
# Encrypt all the files in the directory
for root, dirs, files in os.walk(directory):
for file in files:
filePath = os.path.join(root, file)
pyAesCrypt.encryptFile(filePath, filePath + ".aes", password, bufferSize)
print("Encryption complete!")
This script uses the pyAesCrypt
library to perform the encryption. To use the script, you will need to install pyAesCrypt
using the following command:
pip install pyAesCrypt
You will also need to modify the directory
variable to specify the directory that you want to encrypt. The password
variable should be set to the password that you want to use for the encryption.
Note that this script will encrypt all the files in the specified directory and its subdirectories. It will create encrypted versions of the files with the extension .aes
, so the original files will no longer be accessible. To decrypt the files, you can use the following script:
import os
import pyAesCrypt
# Set the directory that you want to decrypt
directory = "C:\\example\\"
# Set the password for the encryption
password = "password123"
# Set the buffer size
bufferSize = 64 * 1024
# Decrypt all the files in the directory
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".aes"):
filePath = os.path.join(root, file)
pyAesCrypt.decryptFile(filePath, filePath[:-4], password, bufferSize)
print("Decryption complete!")
This script will decrypt all the files with the .aes
extension in the specified directory and its subdirectories. It will create decrypted versions of the files, so you will be able to access the original files again.