Hi there,
first of all I have a file named "directory.txt" which contains all
filenames of a certain directory (some thousand files or so) and looks like
this:
importantfile1.doc
nicework.ppt
salary09.xls
salary08.xls
....
All these files need to be encrypted with a special program (GnuPG, but that
is rather unimportant).
Therefore I need to create a batch file that reads the first line of
"directory.txt", puts the information into a variable and then deletes that
line from the file and then passes the information in the variable on to the
encryption program (as a parameter, see below).
It is important that the line is deleted from the "directory.txt" before the
encryption program is being executed, so that another thread of that batch
file that would be started some time later does not start to encrypt the same
file again.
For now, I have already created the following "one-liner":
FOR /F "delims=" %%i IN ('TYPE directory.txt') DO echo
secretpassphrase|gpg.exe --passphrase-fd 0 -v -c "%%i"
What I have not been able to accomplish yet, is to delete the line in
question from the directory.txt BEFORE gpg.exe is being executed.
In some imaginative pseudocode I imagine this would look somewhat like this:
========================
x = CountLines(directory.txt);
FOR i = 0 to x DO
BEGIN
$filename = READLINE(i) from directory.txt;
DELETELINE(i) from directory.txt;
echo secretpassphrase|gpg.exe --passphrase-fd 0 -v -c "$filename"
END;
========================
I hope you can understand my problem and help me somehow to find the
commands to accomplish this.
The goal is to be able to start this "program" like five or ten times in
parallel, so that the task of encrypting all files in the directory is
accomplished faster that if only one file could be encrypted at a time.
I would also happily try to do this using VBS or something like that. The
only point is that the line that executes the encryption program, namely:
echo secretpassphrase|gpg.exe --passphrase-fd 0 -v -c "$filename"
should stay as it is (except for the variable containing the filename at the
end, of course). This is, because the passphrase can only be entered
interactively (which is done here by a pipe that passes it on to fd0, kind
of).
Any help will be appreciated very much!
Thank you all in advance,
yours,
officer07
Bookmarks