F
F
favor1t2017-07-03 12:13:36
PowerShell
favor1t, 2017-07-03 12:13:36

Batch file for archiving files in a folder (each file in a separate archive and with a unique password)?

Hello! Faced with the task of archiving all files in a folder, encrypting each file with a separate password.
all files for archiving are placed manually in a folder, respectively, you can also set a name for them. Based on my knowledge, it seems to me that it is easier to create text files with passwords with names similar to the names of files in the folder for archiving, and through a loop
-> read the file name in the folder for archiving
-> write it to a variable
-> run a comparison on the contents of this variable with the names of the password files in the folder
-> read the contents of the txt file with the password and write it to a variable
-> start archiving the file with the password specified in this variable
If it's easy for some guru to sketch out the syntax, I will be grateful :) I myself got a little confused about the filters for variables :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2017-07-03
@fawor1t

The password can be randomly generated: %RANDOM%
True, the random number generator in cmd is still the same, in my opinion it just takes the time in seconds from the start of the OS and passes it off as a random number. But for your purposes it will do.
Then the passwords can be added to a file along with the names of the encrypted files.

@echo off
setlocal enabledelayedexpansion
for %%a in (*.txt) do (
set "password=%RANDOM%"
set "filename=%%~a"
echo.password = !password! file = !filename!
7z.exe a -t7z -p!password! "%%~dpna.7z" "%%~a"
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question