Double click on the zip file has to self-extract the file in the specified path - windows

I have filename.zip file and if double click the file it has to extract the file in the desired location("c:\user\username"). I have tried using the batch file but didnt give me the required result.
#echo on
#set nested=%nested%Z
set _dest=c:\user\username
if NOT EXIST %_dest% md %_dest%
So if i double click on zip file it has to execute batch file to place file in the destination folder path.How can i do that?

If I understand correctly, you simply want to extract a .zip archive to a previously defined directory c:\user\username, when the user clicks that .zip archive.
No, this is not possible.
A .zip file has no default extraction destination. Nor has is a way to execute scripts upon extraction. It is just a container for compressed data. When you click it, your OS runs a program configured to handle .zip files, allowing you to view the contents, extract the contents, etc - but what and how exactly, is up to the user that clicked the file.
What you effectively want to have is an installer. Here are some pointers for options to do that:
Microsoft IExpress
Nullsoft Scriptable Install System (NSIS)
Quasi-installer using 7-zip self-extracting archive

Related

How to use Windows Batch File to mass unzip files and saving them in specific folders?

I got the code to mass unzip from this link. But it unzips everything in the folder where the batchfile exists. I want it to unzip it to specific folders or its individual folders.
Note: my bz2 files are in various folders outside the folder where the batchfile exists.
Here's the script that i used :
for /R "C:\Users\victor\Desktop\MASTERS\color feret\disc 1\data\images" %%I in ("*.bz2")
do ("%ProgramFiles%\WinRAR\WinRAR.exe" x -y -o"%%~dpnI" "%%~fI")
Can someone enlighten me how to do it?
And also if possible, can anyone explain to me what are the arguments for? "x , -y -o %%dpnI " etc. Thanks
You do not need a batch file for this process at all. Start WinRAR, select all the archives you want to extract, click on Extract To in toolbar, select the base destination folder, check the option Extract archives to subfolders in Miscellaneous group and press button OK. That's it.
From a command line in a console window with current working directory being the directory containing all the *.bz2 files to extract:
"%ProgramFiles%\WinRAR\WinRar.exe" x -ad -y *.bz2 C:\Temp\
There is no need for a for loop as WinRAR supports wildcards for archive file names.
And with option -ad the archive file First.bz2 is extracted to folder C:\Temp\First, archive file Other.bz2 is extracted to C:\Temp\Other, and so on. With checking option Extract archives to subfolders in GUI, you use option -ad.
Help of WinRAR contains the page Switch -AD - append archive name to destination path. Click in menu Help on Help topics. On tab Contents open Command line mode and open Commands and Switches. Also text file Rar.txt in program files folder of WinRAR contains a description for command x and the options -ad and -y and all other commands and options for console version Rar.exe.
But if you want to use nevertheless a for loop and want to know what %%~dpnI and %%~fI mean, open a command prompt window, enter either help for or for /? and read.

Making single executable includes all program file and folders with nsis?

I have zip file containing my installation files. I'm extracting this zip and copying these files into installation directory with the script shown below:
ZipDLL::extractall "$OUTDIR\demo.zip" "C:\myapp\demo\"
if I remove zip file from $OUTDIR than installer is not able to find zip file as expected. What I want to do is embedding this zip or its extracted folders into exe itself. I added
File -r "$OUTDIR/demo"
but this script didn't worked as well.
When you use the ZipDll plugin, you are referring to the file you want to process (demo.zip) by using its place at run time: along the installer.exe.
When you use the File statement to embed some files into the produced installer, you need to refer to the files by using their place at compile time.
Replace the $OUTDIR in the File statement by the path relative to the .nsi script.
BTW, you should take the habit to check at the compilation log, NSIS probably tells you about that kind of problem when paths are incorrect at compile-time.

Executing binary files with a shebang

I created a simple program that takes the path of a directory as an input, creates an archive of that directory (converting it into a single file), adds a shebang to that file (so that the contents of the file can be easily extracted), and writes the file to the base directory of the specified path.
The problem is that the file does not extract itself when I double click on it. Instead the operating system (I'm using Ubuntu 11.10) tries to open it with gedit. This obviously shows the shebang, random gibberish, and the contents of the archived files.
I made the file executable, first by using chmod +x; and when it still didn't work I tried chmod 777. However it still refuses to execute the file with the shebang when I double click on it. Perhaps this is because it's not a pure text file.
Interestingly when I try to execute the file directly from command line it reads the shebang and extracts the contents of the archive properly. So there's nothing wrong with my file format. I don't know much about what operating systems do when you double click on a file but I would sure like to understand.
It surely makes no sense to add a shebang to a file if you still need to manually execute it from the command line. One advantage could be that you don't need to specify the program to open it with but I believe that's hardly an advantage. Any help will be greatly appreciated.
Update 1:
The program that creates the archive is called opm. It can be installed via the node package manager using the following command:
npm install opm
After that you simply use opm to pack and unpack directories for you. For example if I have a directory called test in my home directory then I can open a terminal and execute the following command to pack it:
opm test
This will create an archive of the directory called test.pack in the home directory. The .pack file has the shebang #!/usr/bin/opm. Opening a file with the extension .pack with opm tells it that it's an archive and opm unpacks it in the same directory.
Note: Change the name of the test.pack file if you do not want it to overwrite your existing test directory.
I added the shebang to the .pack file so that it would extract itself when I opened it. However that doesn't seem to work. Nevertheless if I run one of the following command then it works:
./test.pack
You may check my source code and make any modifications to the program as you may wish to.
Update 2:
Alright I created the following .desktop file for opm and stored it in the $HOME/.local/share/applications/ directory:
[Desktop Entry]
Type=Application
Version=1.0
Encoding=UTF-8
Name=OPM
GenericName=Object Packer and Minifier
NoDisplay=true
Comment=JavaScript Package Manager
TryExec=opm
Exec=opm %f
Terminal=false
MimeType=application/opm
Now I was able to associate .pack files with opm by right clicking on a .pack file, going to the Properties window, the Open With tab, and setting opm.desktop as the default application. Now I am able to unpack a .pack file by simply opening it.
However I would like to know how to associate .pack files with the mime type application/opm. Currently the .pack files are associated with application/x-java-pack200. How do I do so? Is it better if I use a different extension (e.g. .opm)? By associating the packed archives with the mime type application/opm will the OS open them with opm by default without having to explicitly set a default application from Properties > Open With?
If there's already a MIME-type associated with .pack then you'll want to use a different extension (.opm) to associate with your MIME-type (application/opm). The way you automatically associate a program that opens files of a specific MIME-type is with xdg-mime .
Alternatively,
Edit ~/.local/share/applications/mimeapps.list and put your MIME/application combo under [Default Applications] like so:
[Default Applications]
application/opm=opm.desktop;
Place your opm.desktop file in ~/.local/share/applications/ folder. (You've already done this)

How to find parent ZIP file from arguments when double-clicking in Windows Explorer - .NET 4.0

In Windows Explorer, when you open a ZIP file and double-click a file, say a JPEG file (.jpg), Windows extracts the JPEG file to a temporary folder, and passes the temporary file name to the associated program as the one and only argument, such as "C:\Users\jprice\AppData\Local\Temp\Temp1_<>.zip\<>.jpg"
I noticed that some applications, like the Windows Photo Viewer in Windows 7 know what ZIP file the temporary file came from. You can click next and previous and get the next/previous files from the ZIP file (as you do, they are also extracted to temporary files).
I've googled and prowled through system.io.packaging, but I can't figure out how to get the path of the original ZIP file (the file name is part of the temporary file path).
It's not done with the shell-->open command, Windows Photo Viewer only gets the temporary file name as far as I can tell.
The Photo Viewer command line is
%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1
Which doesn't help. I did use ProcessMon to watch Photo Viewer and saw it read the .zip file (probably using zipfldr.dll) but could not discover how it knew where the original zip file was.
When I try it, I notice that WinZip initializes the spawned process's current working directory to the folder that the .zip resides in. If you can extract the .zip filename from the temp file path (and older OS versions did not do that), then you can reconstruct the original .zip file path.

iexpress hard-coded extraction destination folder?

I'm using iexpress to make a self extracting executable. Is there a way I can hard-code an extraction destination folder (preferably into a temp folder somehwere) so as to not have the extraction pop up the "Please type the location where you want to place the extraced file." dialog?
There's no direct way to do this. (You can see my other answer for a longer explanation about it.)
The easiest solution is to make an IExpress archive that runs an "installation program", which is really just a batch file that copies the extracted files where they're needed.
In IExpress, you'd launch the batch file like: cmd /c persist.bat. And persist.bat looks something like:
#echo off
xcopy /y * "%temp%\persistent\"
del /f "%temp%\persistent\persist.bat"
(The last line is a nicety to hide the fact that you used this batch file to copy the extracted archive.)
Yes, this is possible through the use of an .INF file when you select "Extract files and run an installation command". You must set the .INF file as your Install Program and under the DestinationDirs section you would put the path to the directory you want the files to go to. Here is an example of an .INF file:
[version]
signature="$CHICAGO$"
[DefaultInstall]
CopyFiles=install.files
[DestinationDirs]
install.files=-1,"C:\Program Files\MyCustomDir"
[install.files]
MyFile1.txt
MyFile2.bmp
So this sample shows that the installer will install to C:\Program Files\MyCustomDir. The files under the install.files should list all the files you want to copy to that folder. They must be included in your installer when you are selecting the files to add.

Resources