Solved

Right Click - Send arguments.

Posted on 2004-04-17
5
171 Views
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.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.
0
Comment
Question by:lekhak
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:wtrmk74
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 !
wtrmk74
0
 
LVL 83

Accepted Solution

by:
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.

====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
 
LVL 1

Author Comment

by:lekhak
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:\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
 
LVL 1

Author Comment

by:lekhak
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\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
 
LVL 83

Expert Comment

by:oBdA
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.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

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…
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now