Batch Script to execute exe based on file string [SOLVED]
Posted: 17 Apr 2012 02:16
Hi,
First off, I'm very new to batch, but have varied experience in other languages. I have a number of files that taken of an encrypted FTP server that need to be run through an encryption programme. There's a large number of files so I need a script to do this. I can get the script to loop through the files and execute the decryption fine (with the appropriate key), but I want to be able to run the decrypt only if the first 3 letters of the filename are "mar". The encryption executable is in the same folder as the files and the output just appends .xls to the file name.
I'm seriously stumped here as based on everything I've read what I have below should work. I'm running on winXP 32bit sp3 if that makes a difference. Thanks for any help,
First off, I'm very new to batch, but have varied experience in other languages. I have a number of files that taken of an encrypted FTP server that need to be run through an encryption programme. There's a large number of files so I need a script to do this. I can get the script to loop through the files and execute the decryption fine (with the appropriate key), but I want to be able to run the decrypt only if the first 3 letters of the filename are "mar". The encryption executable is in the same folder as the files and the output just appends .xls to the file name.
I'm seriously stumped here as based on everything I've read what I have below should work. I'm running on winXP 32bit sp3 if that makes a difference. Thanks for any help,
Code: Select all
:: file decryption
@echo on
:: loop through files to decrypt
for %%x in (*) do (
set var=%%x:~0,3%
@echo %var%
if "%var%"=="mar" (
des -D -u -k "ENCRYPTION KEY" %%x %%x:~-8.xls
)
)