Solved

Right Click - Send arguments.

Posted on 2004-04-17
5
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85

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 85

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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