Right Click - Send arguments.

I'm new to this stuff. So, please bear with me.

I wanted to use javas' jar tool to do all zipping/unzipping. So I created two batch files...
1. zip.bat which contains:
      jar cvfM abc.zip abc
2. unzip.bat which contains:
      jar xvf abc.zip

Then I associated zip.bat to "Folders" and unzip.bat to "zip files" in "Folder Options"

What I want to do is send the folders name to the script - zip.bat;
and zip files name to the script - unzip.bat.
All I'm able to do right now is use the same constant names "abc" for folder and "abc.zip" for the zip file.

How do I make it dynamic?
Essentially, how do I send the name of the right clicked file/folder as an argument to an application?

-Thank you.
LVL 1
lekhakAsked:
Who is Participating?
 
oBdAConnect With a Mentor Commented:
You can set your associations back to the default. Instead, here's a script that handles both zipping and unzipping.
Save it someplace as "JarArchive.cmd" (or whatever you want to call it), then in your user profile in the "SendTo" folder, create a shortcut to this script, named, for example, "JarArchive". If you feel like it, replace the shortcut's default symbol with the jar symbol ...
Now you can right-click on a file/folder (or highlight several files/folders) and send them to "JarArchive". The script will determine whether the selected file/folder is already an archive (you can select which file types should be considered as archives), in which case it will unzip it; if it's not an archive, it will zip it to the name of the file/folder, with the extension ".zip". It can handle it even if you send an archive and a folder at the same time: the archive will be extracted, the folder will be zipped.
All you should have to adjust for this to work are the settings at the beginning.
Currently, the script is in test mode; it will only display the commands it would issue otherwise, so that you can test if it works correctly. Remove the "ECHO"s and the "PAUSE" where indicated to run the script for real. (The error handling implemented relies on jar returning an errorlevel, which I can't verify since I'm not using it.)
The script will of course work from the command line as well. Simply start it with the files/folders to be handled as arguments.

====8<----[JarArchive.cmd]----
@echo off
setlocal
:: *** Arguments for jar when zipping:
set ArgZip=cvfM
:: *** Arguments for jar when unzipping:
set ArgUnzip=xvf
:: *** File extensions to be unzipped, including the ".", separated by a space (example: .zip .rar):
set UnzipExt=.zip
:: *** Default extension for the created archive (if zipping), including the ".":
set ZipExt=.zip
:: *** Color scheme; enter "color /?" in a command window for details.
set ColorScheme=70

set Errors=0
color %ColorScheme%
:loop
if .%1.==.. goto leave
set Source=%1
set Source=%Source:"=%
set SourceExt=%~x1
set Target=%~dpn1%ZipExt%

:: *** Check if the extension is in the "unzip" archive list:
set Unzip=FALSE
for %%a in (%UnzipExt%) do if /i "%%a"=="%SourceExt%" set Unzip=TRUE
if /i %Unzip%==TRUE goto Unzip

:: **********************************************************************
:: *** Zip the source:
title Archiving %Source% ...
echo Archiving %Source% to %Target% ...
:: *** Test mode: remove the "ECHO" in the next line to "arm" the script:
ECHO jar %ArgZip% "%Target%" "%Source%"
if errorlevel 1 set /a Errors+=1
shift
goto loop

:: **********************************************************************
:: *** Unzip the source:
:Unzip
title Extracting %Source% ...
echo Extracting %Source% ...
:: *** Test mode: remove the "ECHO" in the next line to "arm" the script:
ECHO jar %ArgUnzip% "%Source%"
if errorlevel 1 set /a Errors+=1
shift
goto loop

:: **********************************************************************
:leave
title Done.
:: *** Wait for a key if an error occured:
if %Errors% GTR 0 (
  echo There were %Errors% errors during zipping or unzipping.
  pause
)
:: *** Test mode: remove the "PAUSE" in the next line to close the
:: *** script window automatically if no error occured
PAUSE
====8<----[JarArchive.cmd]----
0
 
wtrmk74Commented:
you will have to use the Microsoft SendTo Services

locate the folder " SendTo " in your system and add the script file to this folder.....

the trick will be connecting to the current directory

possibly VB Script

I'll try to research some avenues for you !
wtrmk74
0
 
lekhakAuthor Commented:
Thanx oBdA.

Your script doesnt seem to work for me.

When I try to zip a folder "abc" I see this in the opened cmd window:
     Archiving E:\ban to E:\ban.zip ...
     jar cvfM "E:\ban.zip" "E:\ban"
     Press any key to continue . . .
But, on pressing a key no ban.zip is being created.

When I try to unzip a zip file "if32.zip" I see this in the opened cmd window:
     Extracting E:\dwnlds\if32.zip ...
     jar xvf "E:\dwnlds\if32.zip"
     Press any key to continue . . .
But, again the zip isnt being unzipped.

If it makes any difference, I'm using Windows 2000 Professional.
0
 
lekhakAuthor Commented:
Sorry oBdA,

I did not check your script properly and did not follow your instructions to
<<remove the "ECHO" in the next line to "arm" the script:>>
The script works now.

I'm awarding you the points for getting it right.
But, I wish to point out a bug in your script.

If I were to create a zip "C:\testing\abc.zip" from "C:\testing\abc"
and move the zip file to a different location, say "E:\"
and try to unzip there, it still unzips to "C:\testing\abc" and not "E:\abc".

Your script seems to tie the zip file to the exact absoulte path instead of a relative path.

Anyways,
Thanks oBdA.
0
 
oBdACommented:
Well, that's not directly "my" doing; that's due to the zipping or unzipping arguments passed to jar. Since I'm not using it, I don't know which ones to use best, but you can easily change them at the beginning of the script.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.