0

I'm using this piece of code to extract my cbr/cbz files to the folders. Since I have a comic reader opens these files by default. I made this batch file and put it under shell:sendto So I can right click a cbr file and extract it to a new folder there. It works for one file at a time.

cd /d %~dp1

"C:\Program Files\WinRAR\WinRAR.exe" x %1 "%~n1\"

It works for a single file. But I like to select 5-6 files in same folder, right click them and select send to- my batch command and extract all to their specific folders.

So I did this batch file for it:

cd /d %~dp1

:start

"C:\Program Files\WinRAR\WinRAR.exe" x %1 "%~n1\"
SHIFT
if not "%1"=="" (goto :start)

pause

But it doesn't work. How can I make my batch file recognize the files I selected while right clicking?

Edit:

I thought maybe the directory change is bugging the code, so I remove that part. Still not working for multiple files, fine for one.

:start

"C:\Program Files\WinRAR\WinRAR.exe" x %1 "%~dp1%~n1\"
SHIFT
if not "%1"=="" (goto :start)

pause
toolic
  • 57,801
  • 17
  • 75
  • 117
kopgamer
  • 1
  • 1

1 Answers1

0

I think I got it, if you have another suggestion please say so.

for %%A in (%*) do "C:\Program Files\WinRAR\WinRAR.exe" x %%A "%%~dpA%%~nA\"
pause

This seems to do the trick, I hope I won't get any errors.

kopgamer
  • 1
  • 1
  • It will work in many cases, however, if any of your selected file names/paths have characters which are problematic they aren't always doublequoted when passed from the GUI. – Compo Apr 21 '20 at 12:24
  • @Compo Thanks for your input. Any suggestions for that? Maybe a name check before the script? – kopgamer Apr 21 '20 at 14:38