Right Click - Send arguments.

Posted on 2004-04-17
Last Modified: 2010-04-13
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
2. unzip.bat which contains:
      jar xvf

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 "" 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.
Question by:lekhak
  • 2
  • 2

Expert Comment

ID: 10852028
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 !
LVL 84

Accepted Solution

oBdA earned 500 total points
ID: 10853104
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.

@echo off
:: *** 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):
:: *** Default extension for the created archive (if zipping), including the ".":
:: *** Color scheme; enter "color /?" in a command window for details.
set ColorScheme=70

set Errors=0
color %ColorScheme%
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
goto loop

:: **********************************************************************
:: *** Unzip the source:
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
goto loop

:: **********************************************************************
title Done.
:: *** Wait for a key if an error occured:
if %Errors% GTR 0 (
  echo There were %Errors% errors during zipping or unzipping.
:: *** Test mode: remove the "PAUSE" in the next line to close the
:: *** script window automatically if no error occured

Author Comment

ID: 10855120
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:\ ...
     jar cvfM "E:\" "E:\ban"
     Press any key to continue . . .
But, on pressing a key no is being created.

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

If it makes any difference, I'm using Windows 2000 Professional.

Author Comment

ID: 10855184
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\" 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.

Thanks oBdA.
LVL 84

Expert Comment

ID: 10857931
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.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question