Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to escape special characters on InputFile with Drag and Drop ?  (Read 4630 times)

0 Members and 1 Guest are viewing this topic.

Hackoo

    Topic Starter


    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Hi   ;)
The goal of this code is to drag and drop a file onto the script and it encodes or decodes it in Base64 with Certutil Command.
So my question is : "What can i do to escape special characters when a file to be encoded or decoded have them ?"
Thank you !
Code: [Select]
@echo off
Set "file=%~1"
If "%file%"=="" GOTO:EOF
>nul find "-----BEGIN CERTIFICATE-----" "%file%" && (
 certutil -f -v -decode "%file%" "%file%"
) || (
 certutil -f -v -encode "%file%" "%file%"
)
@EXIT

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: How to escape special characters on InputFile with Drag and Drop ?
« Reply #1 on: October 06, 2019, 01:36:20 AM »
In C++ I have had to escape the escape character such as \\. In Batch you should also be able to do the same by a double escape using a batch escape character. The first escape is saying to escape the literal escape character. https://www.robvanderwoude.com/escapechars.php

Hackoo

    Topic Starter


    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
[solved] How to escape special characters on InputFile with Drag and Drop ?
« Reply #2 on: October 06, 2019, 10:20:48 AM »
I got a solution, so the problem is solved  ;)
Code: [Select]
@echo off
Title Encode and Decode files into B64
setlocal enableextensions enabledelayedexpansion
set "count=0"
set scr="%~f0"
set "cmd=!cmdcmdline:*%~f0=!"
set "args=!cmd:~0,-1!"
set "args=!args:* =!"

for %%f in (!args!) do (
   set /a "count+=1"
   set infull[!count!]="%%~f"
)

for /l %%i in (1,1,!count!) do (
   Set "file=!infull[%%i]!"
)

If [!file!]==[] GOTO:EOF
echo !file! & pause

>nul 2>&1 find /I "-----BEGIN CERTIFICATE-----" !file! && (
certutil -f -v -decode !file! !file!
) || (
certutil -f -v -encode !file! !file!
)
pause
@Exit