I searched with Google but I didn't find something for Windows.
How can I extract several files into several folders?
For example: a.zip, b.zip and c.zip into the folders a, b and c.
I am looking for a command prompt command or a batch file solution.
Thanks
With using WinRAR in GUI mode:
Start WinRAR.
Select all the *.zip files.
Click on icon Extract To in toolbar.
Enter destination folder or browse to destination folder.
Check the option Extract archives to subfolders in group Miscellaneous.
Click on button OK.
In case of you want to know more about those extracting options, click before on button Help.
Or use from command line with current directory containing the *.zip files and all archive files which should be also extracted into subfolders of current directory with name of ZIP file as folder name:
"%ProgramFiles%\WinRAR\WinRAR.exe" x -ad -cfg- -ibck *.zip
How to build such a WinRAR command line?
Start WinRAR.
Click in menu Help on Help topics.
Click on tab Contents on list item Command line mode.
Click on list item Command line syntax, read this help page and copy the bold line into a text editor or into a command prompt window.
Click on tab Contents on list item Commands.
Click on list item Alphabetic commands list and replace <command> in text editor or command prompt window by most suitable command letter for the task.
Click on tab Contents on list item Switches.
Click on list item Alphabetic switches list and replace -<switch1> -<switchN> in text editor or command prompt window by those switches which are useful for the task.
Replace the rest of the WinRAR command line in text editor or command prompt window by the appropriate file and/or folder names.
The short explanation of the most important switch -ad for this task is:
-ad append archive name to destination path
As it can be seen here, WinRAR supports even a wildcard pattern as archive file name for extracting all archives files matching the pattern.
One more method exists with shell integration enabled as by default after installation of WinRAR.
Select the archive files to extract in file manager (Windows Explorer).
Click with secondary (right) mouse button on one of the selected files to open the context menu.
Open context submenu WinRAR if there is such a submenu because of enabled setting Cascaded context menus in WinRAR - Options - Settings - Integration.
Click on context menu item Extract each archive to separate folder.
Related
Can a Windows batch file determine its invoked filename when invoked through a shortcut?
For example, I create real.bat, and create its shortcut named phony.bat (.lnk?)
And invoke phony by double-click on it.
Can this batch file detect the name phony.bat instead of real.bat?
Of course I can just copy it to another name, but when I edit one of them, I have to manually sync the content to all files.
The question is related to Can a Windows batch file determine its own file name?, but different.
As in your you mentioned that you've created the shortcut I assume you can create the with any properties you want.
So right click on your lnk file and change the the target line to:
C:\Windows\System32\cmd.exe /c "set "lnk_call=1"&"C:\PATH\TO\your.bat" "
This will change the icon of the link so to set back to batch file cog click on change icon and find the bat file icon in :
%SystemRoot%\System32\SHELL32.dll
Finally in your bat put this line:
if defined lnk_call echo triggered from lnk file
the lnk_call now can be used to determine if your file is called from double clicking on a .lnk file. I don't think it is possible to detect this from a shortcut that anyone else created.
Oh yeah, I found hardlink useful in this case:
mklink /h <link-name> <source-file>
I can create many hardlinks with different name, and they all points to the same file, so I can freely edit any one of them without manually sync their content.
After building my appplication on Windows using maven (and a little bit of ant) I manually create a Winrar Sfx Installer as follows:
Select files, right click and select Add to Archive
Use Browse.. to create the archive in the folder above
Change Archive Format to Zip
Enable Create Archive Format
Select Advanced tab
Select SFX Options
Select Setup tab
Enter setup.exe into the Run after Extraction field
Select Modes tab
Enable Unpack to temporary folder
Select text and Icon tab
Enter new title
Select setup.ico from the same folder that we invoked winrar from
Select OK
Select OK
But can I automate some/all of this using Windows batch file/ Maven or ant ?
Start WinRAR, click in menu Help on Help topics and open tab Contents. You see there the list items:
Command line mode
Command line syntax
Commands
"A" - Add to archive
Switches
...
Self-extracting modules
All information you need to call WinRAR.exe with the right switches to create an SFX can be found in those help articles.
In general there are two possibilities:
You do what you have already done, but before clicking on final OK, you click on button Profiles on tab General and click on list item Save current settings to a new profile. Then you can call WinRAR.exe with switch "-cpMy SFX Profile". Read the help page for this switch.
You specify all options for creating the SFX archives directly on command line.
For the second possibility something like below can be used as template.
"%ProgramFiles%\WinRAR\WinRAR.exe" a -afzip -cfg- -ed -ep1 -k -m5 -r -tl -iicon"Path to icon file\MyApplicationInstall.ico" "-sfx%ProgramFiles%\WinRAR\Zip.sfx" "-zComment file with full path containing SFX options" "Path to Destination Folder\MyApplicationInstall.exe" "Path to files to add to archive\*"
The content for the *.txt comment file for switch -z can be copied from tab Comment of the dialog opened for creating the archive after selecting all the SFX options.
By the way: I would suggest creating RAR self-extracting archives instead of ZIP self-extracting archives as with RAR compression the EXE file with the right switches for best compression using additionally also solid archive options could be much smaller than with ZIP compression.
So you don't need a batch file or any other application to create a WinRAR SFX archive. A simple shortcut file (*.lnk) with the right command line is all you need to create the SFX archive with a double click on this shortcut whenever you want to create a new SFX for your application.
I have file.txt opened in notepad++.exe
This works with all filetypes (.xlsx .txt .tab .csv .pages .scrivener you get it) on OS X:
I right click the file name using the app I'm in. (On notepad++ on windows, this would be right clicking on my file.txt file.)
A menu pops up, showing me the path to that file. For example /dropbox/work/projectA/subfolderB/file.txt
I choose a certain folder, for example the folder /projectA
That folder opens up in finder.
I want to do this on windows 7. Extra important to do it in notepad++ with .txt-files, since those are part of my GTD-system.
The question is not at all clear about what you want.
Having installed Notepad++ via the normal installer, you should be able to right-click on a file in Windows Explorer (or File Explorer) and select "Edit with Notepad++". That allows any file to be viewed with Notepad++.
The Notepad++ Run menu should contain an entry for Open containing folder that opens Windows Explorer at the folder containing the current file. This command shoul dbe in the file c:\Users\{UserName}\AppData\Roaming\Notepad++\shortcuts.xml. The shortcuts file on My Windows 7 computer contains the line
<Command name="Open containing folder" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_DIRECTORY)</Command>
If you need to alter the shortcuts file then do not use Notepad++, use another editor.
I am trying to create a self-extracting archive that extracts to "%USERPROFILE%\Desktop" with WinRar. However, when I run it, it extracts to the SFX's current directory, not my desktop. Does the path to extract option work at all?
I'm using the 32-bit command line module.
I also checked the 'hide all' box for silent mode which appears to do absolutely nothing and the command prompt window still appears with showing information on what is extracted.
I want that SFX archive extracts the .exe and the folder contained in the SFX file to the desktop without any messages popping up.
Any suggestions?
It is possible to create an SFX RAR archive extracting all files and folders directly to
"%USERPROFILE%\Desktop" without showing a window.
This can be done with WinRAR after selecting the files and folders and clicking on icon Add in the toolbar by
checking on tab General the option Create SFX archive,
clicking on tab Advanced on button SFX options,
entering on SFX tab General for Path to extract the string "%USERPROFILE%\Desktop" which results in automatic selection of option Absolute path which is right,
selecting on SFX tab Modes the option Hide all,
selecting on SFX tab Module the SFX module Default.sfx (WinRAR GUI SFX module),
closing Advanced SFX options window with button OK,
entering on tab General the name for the SFX archive,
and starting compression with button OK.
A command prompt window will be always displayed if module WinCon.sfx is used for the SFX archive as in this case Windows detects automatically on start of the SFX archive that this is a console application and opens a command prompt window in which the console SFX is executed.
Creating such an SFX archive can be done also with a batch file:
#echo off
echo ;The comment below contains SFX script commands>"%TEMP%\SfxOptions.txt"
echo/>>"%TEMP%\SfxOptions.txt"
echo Path="%%USERPROFILE%%\Desktop">>"%TEMP%\SfxOptions.txt"
echo Silent=^1>>"%TEMP%\SfxOptions.txt"
"%ProgramFiles%\WinRAR\Rar.exe" a -c -cfg- -ep1 -idq -m5 -mdg -r -s -sfx -y "-z%TEMP%\SfxOptions.txt" "Path\Name of your SFX.exe" "Path\Folder to add" "Path\File to add"
if errorlevel 1 goto Failure
del "%TEMP%\SfxOptions.txt"
goto :EOF
:Failure
del "%TEMP%\SfxOptions.txt"
echo/
echo Error on creation of "Path\Name of your SFX.exe"
echo/
pause
In this batch file must be modified for usage:
Path to program files folder of WinRAR containing console version Rar.exe and also the SFX module Default.sfx.
Path and name of the SFX archive to create.
Path and name of folder and/or file to add to the archive.
The used switches are explained in text file Rar.txt in program files folder of WinRAR.
One more note on switch -ep1:
Everything up to last backslash in name of folder and/or file to add to archive is removed from name on adding the folder or file to the archive.
On adding a folder to a RAR archive it makes a difference if the folder is specified with or without a backslash at end.
Example:
A directory tree like
C:\Temp
MyFolder
Subfolder 1
Subfolder 2
File X
File Y
is compressed with
Rar.exe a -ep1 -r C:\Temp\Demo1.rar C:\Temp\MyFolder
with following files and folders in archive C:\Temp\Demo1.rar
MyFolder
Subfolder 1
Subfolder 2
File X
File Y
while using
Rar.exe a -ep1 -r C:\Temp\Demo2.rar C:\Temp\MyFolder\
or using
Rar.exe a -ep1 -r C:\Temp\Demo2.rar C:\Temp\MyFolder\*
results in following files and folders in archive C:\Temp\Demo2.rar
Subfolder 1
Subfolder 2
File X
File Y
What I want to do is very simple, yet can't find the way to do it.
In my projects I have several .bat files (I know, I'm old) the perform some tasks like running SqlMetal, etc.
I just want to right-click the file and select "run" or something so the bat is executed. How do I do it?
Note: I know I can use Tools -> External Tools, but it's not what I'm looking for
If each project has a few batch files associated with it then why not include them in the project and add a new external tool and link it with a custom menu item to run the tool? This will give you a list of batch files in each project and a context menu command to run them. The only downside is that it isn't file type specific (it will let you run any file as a batch file).
Here's how to do it...
Create an external tool called "Run batch file"
Set the Command to: CMD.EXE
Set the Arguments to: /c "$(ItemPath)"
Set the Initial directory to: $(ItemDir)
Check the "use output window" checkbox and then Apply to create the command
Note where the new command appeared in the list of commands. The external commands are numbered from 1 starting below the divider bar. #1 is usually "Create GUID"
Now go to Tools -> Customize and select the commands tab.
Select the Context menu radio button and select "Project and Solution Context menus | Item" from the dropdown.
Now use "Add Command..." to add a new command
In the Categories list select "Tools"
From the commands select the "External Command #" that corresponds to the position of the "Run Batch file" custom command you noted the number of in step 5 above.
Move it to the correct position in the list add keyboard shortcuts etc.
Close the dialog.
Now right click on the batch file and you should see a "Run batch file" menu item. This will execute the batch file and show its output in the VS Output window.
Right click the batch file in the Solution Explorer
Select “Open With…” from the context menu
Click “Add…”
In the “Program name” textbox, enter powershell.exe
In the “Friendly name” textbox enter “PowerShell”
Select “Set As Default”
Click OK
via
Check out the Open Command Line Visual Studio extension.
As per the description, it features:
Opening of a command line at the root of the project.
Support for all consoles such as CMD, PowerShell, Bash etc.
Syntax highlighting, Intellisense and execution of .cmd and .bat files.
For files in your solution, a context-menu button shows up.
Alternatively, the keyboard shortcut Shift+Alt+5 can be used when editing a batch file. This makes it really easy and fast to execute any batch file - even ones that are not part of your project.
Right-click a file in the Solution Explorer window, Open With, click the Add button to add your .bat files. Use %1 in your .bat to get the path to the selected file.
Couldn't get any of the above to quite work, but this did (VS 2019/2022):
Right click a .bat file in Solution Explorer and Open With...
Add...
Program: CMD.exe
Arguments: /c %1
Friendly name: Command
OK and Set as Default for double clicking of batch files to run from Solution Explorer as the default (or right click Open With... and select Command if you don't want it the default).
Merely a suggestion: This is a scenario which can be done with the VsCommandBuddy extension. The following configuration is an example:
{
"cmdname": "mk",
"title": "Run MK.BAT",
"description": "Run the MK bat file.",
"cwd": "$(SolutionDir)",
"filename": "cmd.exe",
"arguments": "/C mk.bat",
"async": false
}
You can assign shortkeys as well, so you can invoke your batch files with shortcut keys. Output comes in your output pane.