How to use WinRAR through Batch? - windows

I need some help with a batch file because I am stumped on WinRAR in Batch, as I haven't done/used it before.
Here is the TREE of my Folders including the batch file:
Each RAR file has the same Directory folder name("vegies" folder).
I would like to be able to extract/copy all folders/subfolders inside of each .rar from "Example/Program_Ex/vegie" back one directory into "Example/Program_Ex/vegies" (Dont forget the folder "vegies" already exists in each RAR which I cannot change as these automatically update themselves.)
So basically with a batch file I would like to:
extract "Example/Program_Ex/vegie/random.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random2.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random3.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random4.rar" to "Example/Program_Ex/vegies"
extract "Example/Program_Ex/vegie/random5.rar" to "Example/Program_Ex/vegies"
I also am trying to not specify a drive, more or less because the batch file will be in the correct folder instead using something such as "CD" or "PATH"?
I have looked at some examples around the web and on here of coarse, but I am still unsure the best way to go about this.
The closest example I can find would be this:
#echo off
set destinationRAR=destination_winrar_file
set source=source_folder_path
"C:\Program Files\WinRAR\WinRAR.exe" a -ep1 -esh -ibck -m0 -r -t %destinationRAR% %source%
(Above from http://fredy-invayne.blogspot.com.au/2013/05/example-winrar-batch-file.html)
Can anyone help give examples on how to implement my question please?

#echo off
for %%a in (
"%~dp0Example\Program_Ex\vegie\*.rar"
) do unrar x "%%~fa" -w "%~dp0Example\Program_Ex" -o+
For each file in the indicated path under the folder in where the batch file is stored, extract the content of the file indicating target folder and selecting that existing files must be overwritten.

You can extract all the archives with a single invocation of WinRAR:
"C:\Program Files\WinRAR\WinRAR.exe" x "%~dp0Program_Ex\vegie\random*.rar" "%~dp0Program_Ex\"
The last argument in the above command line specifies the target folder for all the archives. You may want to add the -o+ switch (must go just after x) to specify that all files should be overwritten:
"C:\Program Files\WinRAR\WinRAR.exe" x -o+ "%~dp0Program_Ex\vegie\random*.rar" "%~dp0Program_Ex\"
If you omit it, the archiver will ask you what to do with existing files, if any.

Related

Moving files of a particular File Extension from multiple folders into one specific folder

I'm only started scripting a few weeks ago and have been testing a few scripts I've put together with help from some posted on this site.
Currently I'm struggling and require some help or assistance.
I want to be able to move all files with any particular/given file extension, from within any directory, and any of their sub-directories, if they exist. I just want the files, not the folders copied.
The script works, I'm hoping for anyway, as such:
You enter the directory you want to move the files from e.g. D:\TestMove
You enter the directory you want to move the files to e.g. D:\Test
You enter the file extension of all of the files that you want to be moved from the given directory, and then sub-directories eg. .txt
If the directory you're moving them to doesn't exist, it should be created.
So in my case, I've got the directory D:\Test, with multiple sub-directories, (TestMove\Test2, etc.), and within each of those directories multiple .txt files, (for example). I want to be able to move all of the .txt files from the D:\Test directory to wherever I want.
At the moment, it's just moving the files from the directory I choose, but not from within the sub-directories.
I'm happy to get this script ripped to bits so that I can learn where I'm going wrong.
set /P DMF=Please enter Directory moving from:
set /P DMT=Please enter Directory moving too:
set /P FEX=Please enter File Extension:
if not exist %DMT% mkdir %DMT%
for %%a in (%FEX%) do (
echo Moving all %%a files to "%DMT%" ...
move "%DMF%\*%%a" "%DMT%"
)

"Can't read file" when trying to Exclude directory in batch file

I've been stuck on this for awhile and could use some help.
I'm trying to copy a large folder from a mapped network drive (A:) onto my local PC. I also need to exclude a subdirectory on that drive path called "Images". My current code (backup.bat) is below:
cd %HOMEPATH%\Desktop\%mydate%
xcopy "A:\PROGRA~2\QuadTech" 121\ /e /EXCLUDE:"A:\PROGRA~2\QuadTech\INSPEC~1\Images\"
Error I keep getting:
I've tried shortening the path with "dir /x" and I am sure the path name is correct. Also note that I need quotations as there are spaces in the PATH name.
Why am I getting errors when trying to Exclude this directory??
ANSWERED
I now have my Exclude statement point to my desktop where it reads a list of strings in a txt file.
xcopy "A:\PROGRA~2\QuadTech" 121\ /e /EXCLUDE:C:\Users\QuadTech\Desktop\excldelist.txt
Txt file contents:
\Images\
This is happening because the /EXCLUDE option does not specify files to exclude.
It specifies files containing lists of files to exclude.
More info by typing xcopy /?, though I am sure you know that.
(I know, I missed it too in the beginning; sometimes it is just a matter of having a second pair of eyes.)

Batch file to copy files from multiple folders to a single folder, overriding if date is newer

I would like to be able to copy all files from various folders and combine them into a single folder using a Windows batch file. That is fairly easy to do for me. But if the file already exists on the destination, I would like it to only override the file if it's newer.
copy c:\pics\ to d:\
Thanks.
You can use xcopy for more options if the source dirs are 2-3-5 (write separate xcopy lines for each). If the dirs are too many, you can use archiver like WinRar (or its command line rar.exe) with #list option where are stored the source dirs. In the batch file call RAR 2 times - first to pack all source files to one archive, then to unrar them in single folder (with E option, not X). Finally, you delete the .rar file. See the extra options to skip older files, omit prompts, etc.

How to copy war file into a particular destination using batch command?

SET src="C:/Users/Neonous/Desktop/New folder/Package/Project-1.war"
SET dest="C:/Program Files/Apache/webapps"
xcopy %src% %dest% /E
I tried the above script to copy war file. its extracting and creating some unwanted directories in to the destination location.
i want to copy the zipped file.... as such Project-1.war.
Simple :
copy %src% %dest%\Project-1.war
I don't know why you want to use xcopy if you want to copy the file only.
If you want to do something else please specify.
Also use backslash" \ " to separate directories and specify file name for targeted destination.
Hope this helped,
Yours Mona.

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