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

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.

Related

"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.)

How to use WinRAR through Batch?

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.

Batch File to store backup files with timestamps

I have two folders in the same drive. I want to create backup of an access database. I need to copy the main file, append the name with the date and time and store it in a different folder.
Source Folder: G:\PMO\Talent Mgt\Data
Source file: Talent_Management_Data.accdb
Destination File: G:\PMO\Talent Mgt\Archive\Talent_Management_Data.accdb_20120101
Any suggestions?
You can achieve this by using for command to execute copy for each file. A simple batch file would be:
cd "G:\PMO\Talent Mgt\Data"
for %%A in (*.accdb) do copy %%A ..\Archive\%%A_%date:-=%

Can we use robocopy to copy files instead of folders

I need to copy a particular file from one location to another., Is it possible to use robocopy to do same.
Whilst Robocopy can be persuaded to copy a single file it is much simpler to use copy or xcopy.
Yes, either wrap it in an an exec or use the Robocopy that is wrapped as part of the msbuild extension pack see:http://www.msbuildextensionpack.com/help/4.0.3.0/index.html
You want to use the MSBuild.ExtensionPack.FileSystem.RoboCopy task.
Makes copying much quicker.
I was trying to figure this problem out. I finally found my own solution and maybe it will help.
I noticed that the syntax used to select the entire directory could be used to select a single file.
ROBOCOPY "*" "Directory source" "Directory Output unc path or non"
The above code will copy everything from the directory source folder to the directory output path.
Let's say you only wanted to copy 1 file from the directory source named "test.txt"
In order to do that use the following code:
ROBOCOPY "*test.txt" "Directory source" "Directory Output unc path or non"
Thats about it. It works really well and will only copy the file name you want.
Alternatively you can use
ROBOCOPY "*.txt" "Directory source" "Directory Output unc path or non"
to copy out all text documents from the directory source.
Similarly this will also work with any .ext
.zip .exe .txt .pdf etc..
I signed up to answer this question with a better method. Let me know if I succeeded.

Windows Batch Copy file by filename

The file I want to copy is located in "C:\Report\" and the filename I want to copy is something like "rptXXXX.txt".
What I want to do is write a batch that copy the file that the filename is start with "rpt".
The destination folder is "F:\Project\Report\".
This should work, you can use an * as a wildcard:
xcopy e:\foo\rpt*.txt e:\foo2
or in your case,
xcopy C:\Report\rpt*.txt F:\Project\Report\

Resources