Post Build event xcopy - exclude some set of files - batch-file

I want to copy some of the files to the specific folder after the successful compilation of the project. I have written a post build event as mentioned below:
xcopy "$(ProjectDir)bin" "$(TargetDir)..\..\Support Files\DBUpgradeUtility\" /Y
Note: the output path of my project has been set to bin folder for debug and release both the mode.
The above mentioned build event worked fine and all the files present under bin folder has been copied to destination folder. But along with the required files, the ‘vshost.exe’ files also copied, I don’t’ want this file. So, I have used the exclude parameter of xcopy build event as mentioned below:
xcopy "$(ProjectDir)bin" "$(TargetDir)..\..\Support Files\DBUpgradeUtility\" /Y /exclude:$(TargetDir)..\..\Support Files\DBUpgradeUtility\*.vshost.exe
With the above build event, the compilation failed and the error was:
The command "xcopy "C:\TFSWorkspace\FASTER.Web -
v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin"
"C:\TFSWorkspace\FASTER.Web -
v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin....\Support
Files\DBUpgradeUtility\" /Y /exclude:"C:\TFSWorkspace\FASTER.Web -
v6.3.Sprint.06\Source\Installer\Application\DBUpgradeUtility\bin....\Support
Files\DBUpgradeUtility*. vshost.exe" exited with code 4.
I have also googled for exclude parameter and then written the build event mentioned above. I cannot find what I am missing here or what I did wrong.
Please help me on this.
Thank you.

The /exclude option of the xcopy command works differently - it allows you to specify files which contain exclude filters:
Specifies a list of files. At least one file must be specified. Each
file will contain search strings with each string on a separate line
in the file.
When any of the strings match any part of the absolute
path of the file to be copied, that file will be excuded from being
copied. For example, specifying the string, \obj\ or .obj will exclude
all files underneath the directory obj or all files with the .obj
extension.
Therefore you may create a new file in your project (for example $(ProjectDir)excludes.txt) and add this line:
vshost.exe
Then change the option in your xcopy command to:
/exclude:"$(ProjectDir)excludes.txt"
This excludes all files containing vshost.exe in their absolute path. If you have to exclude other files, just add a new line to the file.

Related

Make a exclusion list + files list using winrar command line

I made this script below to make a backup of some files. It works fine, but i wanted make a list for the files that need be skipped from compressing.
For example:
my list.txt has all the files that will be compressed. But i wanted to make another list for the files that need be skipped, like exclusion_list.txt. Actually i put all files that i want be ignored from compressing into the command line, as shown below -x*\Test1 -x*\Test2.
But i really wanted to make a exclusion list for not keep changing the command line everytime i need to exclude a file or folder.
How i can do it?
"%winrar%\winrar.exe" a -x*\Test1 -x*\Test2 -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
From the documentation: the exclusion option -x also supports a list file when it is preceded by #:
"%winrar%\winrar.exe" a -x#exclusion_list.txt -ibck -ep1 -ilog%userprofile%\Desktop\log.log "compressed %date:/=.%.rar" "#list.txt"
with the file exclusion_list.txt containing:
*\Test1
*\Test2
By the way, there is even a console version of WinRAR, called rar.exe, which is a non-GUI version.

Move all the contents of a folder with a .bat

I using the following syntax to move all the files inside a folder, to another folder
set OGGI=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%
move C:\DOCUMENTALE\dms_in\*.* C:\DOCUMENTALE\dms_backup\%OGGI%\
This syntax is working with files, but which syntax I have to use if I would move also folders?
The problem is that this path C:\DOCUMENTALE\dms_in\ contains folders automatically generated. I don't know how many folders there are in or which names they have.
I did some attempt but I didn't figure it out
Thanks
An solution to this is to use the command ROBOCOPY instead. It is arguable more flexible.
ROBOCOPY <source> <destination> /MOV /E
/MOV will move the file/folder in question instead of the default copy.
/E will allow you to mirror the directory structure of the target folder if there are any folders within the folder including empty ones
Note: you may need to use quotation marks for the source and destination if either path contains spaces.
Another neat feature of Robocopy is that it will show you what is it doing; what is being copied and too where, how long it takes etc. And if it goes wrong due to paths for example, it will tell you.
You can also browse ss64.com for more help and examples to fit your needs.

Batch - Extract many zip, rename files extracted in a same directory

Hi, I have many zip files located at g:\toto. These zips contain some files. I would like to extract all zip in a same directory (g:\toto\extracted) then rename various files of the zip.
Example 1 :
www_12567.vp.zip : 3 files : alpha.doc, beta.xls, teta.doc
I would like after extraction, files are renamed with the name of the zip
www_12567.vp.alpha.doc, www_12567.vp.beta.xls, www_12567.vp.teta.doc
Example 2 :
www_12.vp.zip : 3 files : al.doc, bea.xls, tta.doc
www_12.vp.al.doc, www_12.vp.bea.xls, www_12.vp.tta.doc
I found this question, but it talks about .txt and the zip contain one file, so, it doesn't work.
Without knowing the contents of the archive you can't know which files to rename, because you are putting them into a directory that may already contain other files.
This, however, would be much easier if there was a dedicated directory to put the files temporarily. Here's how you could use it:
#ECHO OFF
SET "srcdir=G:\toto"
SET "tgtdir=G:\toto\extracted"
SET "tmpdir=G:\toto\extracted-tmp"
FOR %%Z IN ("%srcdir%\*.zip") DO (
unpack "%%Z" with your favourite tool into "%tmpdir%"
FOR %%I IN ("%tmpdir%\*") DO MOVE "%%I" "%tgtdir%\%%~nZ.%%~nxI"
)
Of course, the temporary directory would need to be empty before running the batch file. You could add DEL "%tmpdir%\*" somewhere before the loop to make sure it is.
One other note is, the above assumes that the archives do not contain subdirectories or, at least, that the files are extracted without subdirectories.
UPDATE
If you are using the 7-Zip archiver to work with .zip files, then this is how your extract command might look:
7z e "%%Z" -o"%tmpdir%"
Disclaimer: I'm not an active user of 7-Zip. This is what I used as a reference to come up with the above command:
7-Zip Command-Line Examples

Command Prompt and batch files

I'm trying to copy a number of files from a directory. I want to include the file path from the base of this particular directory tree, however, I only have a list of the file names to go by. Is there a way to copy either:
a list of files with their directories appended to the beginning in a .txt file
a copy of the folders in the directory with copies of the files placed in their original places in the original directory.
Each file in the directory has a unique name.
I've looked all over google, but the closest I've found is xcopy, which I don't believe is capable of this.
Thanks!
For the second option you can use xcopy /s or robocopy /s. Both are great tools for this kind of job.

XCOPY exclude list ignored after first exclusion

I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.

Resources