tags:

views:

147

answers:

3

dear all, I have a batch file as under:

@echo off
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\vipul.zip" files vipul.xls
copy vipul.zip "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy vipul.zip "E:\Valuations\2009"
exit

HERE vipul.xls is the file on my desktop which is to be copied to my briefcase and same is to be ziiped and then sent to E\valu...folder. Alteration i want here is as under: every time the file name is getting changed, e.g. it may be sanj.xls or lago.xls and so on. (in place of vipul.xls), so how i can do this? Just like there is printdir.bat file in xp

A: 

You could have this batch file which works for any file with .xlsextension:

@echo off
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\worksheets.zip" files *.xls
copy worksheets.zip "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy worksheets.zip "E:\Valuations\2009"
exit

Or, if just one that files can exist in some time:

@echo off
set filename=
if exists vipul.xls set filename=vipul
if exists sanj.xls  set filename=sanj
if exists lago.xls  set filename=lago
if "%filename%" == "" goto end
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\%filename%.zip" files %filename%.xls
copy %filename%.zip "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy %filename%.zip "E:\Valuations\2009"
exit
:end
Rubens Farias
but dear i have lots of files on my desktop. i want to waork only with one file, may be vipul.xls or so
Vipul
A: 

but dear i have lots of files on my desktop. i want to waork only with one file, may be vipul.xls or so -- Vipul

Vipul
try that one; and dont create an answer to ask questions: edit your post, ok?
Rubens Farias
A: 

Its not tested, but this should help you:

@echo off

REM check if supplied file name actaully exists
IF "%1"=="" GOTO END
IF NOT EXIST "%1" GOTO END

REM define output file name. Use supplied files name without extension and add ".zip"
SET OutputPath=C:\Documents and Settings\vipul\Desktop\%~n1.zip

"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "%OutputPath%" files "%1"
copy "%OutputPath%" "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy "%OutputPath%" "E:\Valuations\2009"

:END

This batch uses the first command line parameter (%1) as input for the file to package and copy.

The first IF statements check if the file is valid. The SET command set a variable with the name of the file to create (the zip file). The remaining part is mainly the code you already have, but now uses the variables.

EDIT:

To call the batch programm, lets name it package.bat, use a syntax like this:

package "C:\Documents and Settings\vipul\Desktop\vipul.xls"

or

package "C:\Documents and Settings\vipul\Desktop\sanj.xls"

You can also use drag 'n drop and simply drop the file you want to process on the batch file package.bat to start it.

If it doesn't work, add a comment.

EDIT:

To use this batch file in your send to context menu do the following steps:

  1. save the above code in a file and name package.bat (or anything else you want)
  2. put in a location you want.
  3. create a link to the batch file package.bat (right click on the file, chose create link)
  4. move the created link file to your Send to folder (e.g. C:\Documents and Settings\vipul\SendTo
  5. now you can select any file you want and chose the batch file command from your context menu->send to

Hope that helps.

Frank Bollack
Sir, being a very much new to batch file commands, it is hard to understand the above for me. May I have a command like that of printdir.bat? By this command i may right click on individual file and then run the command from context menu, so that it will zip that file, send it to briefcase and then send it to e:\bvaluation folder directly...
Vipul
I don't know 'printdir.bat' but to achive this behaviour, simply add a link to your batch file to the 'C:\Documents and Settings\vipul\SendTo' folder.
Frank Bollack
r u telling that i have to drag vipul.xls to following batch file:@echo offREM check if supplied file name actaully existsIF "%1"=="" GOTO ENDIF NOT EXIST "%1" GOTO ENDREM define output file name. Use supplied files name without extession and add ".zip"SET OutputPath=C:\Documents and Settings\vipul\Desktop\%~n1.zip"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex ""%OutputPath" files "%1"copy "%OutputPath" "C:\Documents and Settings\vipul\Desktop\My briefcase"copy "%OutputPath" "E:\Valuations\2009":END
Vipul
See the latest edits in my answer
Frank Bollack
Sorry, but i can't follow. Let's forget about send to and aall that.I have file a.xls should i drag'n drop that file to below mentioned bat file?@echo offREM check if supplied file name actaully existsIF "%1"=="" GOTO ENDIF NOT EXIST "%1" GOTO ENDREM define output file name. Use supplied files name without extession and add ".zip"SET OutputPath=C:\Documents and Settings\vipul\Desktop\%~n1.zip"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex ""%OutputPath" files "%1"copy "%OutputPath" "C:\Documents and Settings\vipul\Desktop\My briefcase"copy "%OutputPath" "E:\Valuations\2009":END
Vipul
Yes. Create a batch file and save the above code to it. Than you can drag 'n drop a file onto the batch file and it will compress it and copy the output to the locations.But i didn't test so there there might still be some errors in the code.
Frank Bollack
sir,it doesn't work. I have kept ECHO ON and then i realise that the last line it shows is as under:IF ""=="" GOTO END. Sir i don't know how far i'm right, but if possible please try to run on ur computer and do needful. this is very important for me. You can realise this fact that I have spared my full day behind this
Vipul
Okay, try again, I've fixed some errors in the code.
Frank Bollack
still not working error is : goto is unexpected at this time (at this line:IF %1=="" GOTO END)
Vipul
Should work now. But maybe you should make yourself familar with batch programming as it is not to hard to learn and within one day you would have been able to write this on your own and be able to test it on your machine. As a good staring point look here: http://www.robvanderwoude.com/battech.php
Frank Bollack