Batch file renaming -
i come little problem :'( : have many txt files , more , more day , need make back-up of them , encrypt them safety reasons made batch script :
@echo off /r d:\txtwork %%g in (**.txt **.trt) ( certutil -f -encode "%%g" "%%g.bak" echo. >>d:\txtwork\logs\logbak1.txt %time:~0,-6% - made back-up of file - "%%g" )
ok works want make batch decode them , change extension old 1 (from .txt.bak or .trt.bak .txt or .trt ) tried , made :
@echo off /r d:\txtwork %%g in (**.bak) ( certutil -f decode "%%g" "%%g:~0,-4" )
but didn t work tried
@echo off /r d:\txtwork %%g in (**.bak) ( set var_1="%%g" certutil -f decode "%var_1%" "%var_1:~0,-4%" )
it didn't work either. ?
"%%g:~0,-4"
totally wrong;- to retrieve value of
var_1
variable need enable delayed expansion , use!var_1!
instead of%var_1%
although doing bring problem:certutil -f decode "!var_1!" "!var_1:~0,-4!"
expandcertutil -f decode ""something.txt.bak"" ""something.txt""
(note doubled double quotes);
- use next
set
command syntax:set "var_1=%%g"
(note first double quote position).
next code snippet should work:
@echo off setlocal enableextensions disabledelayedexpansion /r d:\txtwork %%g in (**.bak) ( set "var_1=%%g" setlocal enabledelayedexpansion certutil -f decode "!var_1!" "!var_1:~0,-4!" endlocal )
however, use parameter extensions follows:
@echo off setlocal enableextensions /r d:\txtwork %%g in (**.bak) ( certutil -f decode "%%g" "%%~dpng" )
Comments
Post a Comment