You are not logged in.
Pages: 1
I am new to scripting in general and am trying to figure out how to batch encrypt files for us to SFTP to a client.
I've dug around many forums and articles to figure out the right commands to do this and have come up with this (which unfortunately doesn't work):
setlocal EnableDelayedExpansion
REM input dir
SET gpginput=C:\temp\gpgtestin\
REM output dir
SET gpgoutput=C:\temp\gpgtestout\
REM processed dir
SET gpgprocessed=C:\temp\gpgprocessed\
REM Sets working directory to previously defined variable "gpginput"
pushd %gpginput%
REM Clears variable, in case this was not cleared from a previous run
Set FileToEncrypt=
REM Looks for files in the current working directory and sets the filename to the variable FileToEncrypt,
REM encrypts the file, outputs the file to the directory set in "gpgoutput",
REM then finally moves the original file also to the processed directory,
REM to indicate the file has been processed.
for /f %%a in ('dir /b') do (
set FileToEncrypt=%%a
set gpgfileoutput=%gpgoutput%%FileToEncrypt%
gpg -o %gpgfileoutput%.gpg -r Peter -e %FileToEncrypt%
move %%a %gpgtestout%
)
endlocal
What happens is that the script gets stuck, a single ".gpg" file gets created in the input directory (no actual filename), nothing is created in the output directory and no files are moved to the processed directory. (I have 2 test files in the input directory)
Any idea where I went wrong?
Thanks in advance.
Offline
I doubt it matters, but this is on 64-bit Win7.
Offline
When using delayed expansion you need to use ! instead of % when changing and using variables inside a loop
set gpgfileoutput=!gpgoutput!!FileToEncrypt!
gpg -o !gpgfileoutput!.gpg -r Peter -e !FileToEncrypt!
move %%a !gpgtestout!
Offline
What foxidrive said, also you haven't defined "%gpgtestout%" in the code posted.
cmd | *sh | ruby | chef
Offline
Thanks so much for the help.
It works great now!
You folks rock!
Offline
Pages: 1