I tried the following postbuild command in VS to copy all the dlls and other related files into a centralized folder:
robocopy $(TargetDir) $(TargetDir)Bin *.dll *.pdb *.xml /MOVE
It successfully moves them if the Bin folder doesn't have those files yet. But after the second execution, the files are not moved. I am suspecting that it fails because the files in there already exist. Is there a switch to force overwrite without prompting? I looked at the possible switches for robocopy and can't really find the one I am looking for.
I'm guessing that Robocopy is refusing to move files that it detects are the same on subsequent runs. You should be able to force it to do so with the /IS (include same) and /IT (include tweaked) flags - i.e.,
robocopy $(TargetDir) $(TargetDir)Bin *.dll *.pdb *.xml /IS /IT /MOVE
Related
I'm running a TeamCity server and agent on a Windows machine. My last step in the build process is to upload the bin/release filed over to a shared Windows folder on another server through SMB.
I need to delete all filed on the remote server before uploading the new build but can't figure out a way to do it.
I don't see any such option in SMB upload runner.
Yes, you are correct that should be added as a step under build steps, I would prefer a powershell command something like this
robocopy \\%WebServer1%\%SourceFolder% \\%WebServer1%\%DestinationFolder% /E /PURGE /IS /COPY:DT /R:1 /W:2
RMDir /S "%WebServer1%\%SourceFolder%
Where,
/E - Copies sub directories
/PURGE - Deletes destination files and directories that no longer exist in the source
/COPY:DT - Specifies the file properties to be copied, in this case it copies Data and Timestamps
/R:1 - Specifies the number of retries on failed copies, in this case it is 1
/W:2 - Specifies the wait time between retries, in seconds, in this case it is 2 seconds
/s - Includes subdirectories
RmDir will remove the source directory once the robocopy is successful.
If you need to directly remove the files instead of copying and then removing, you could use Move
Reference for Move - https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/move
I would personally prefer copy and delete
I have two folders that I backup from source to destination folder using command:
xcopy /E /Y /I /D
Now I want to delete files in destination folder that do not exist in source folder.
There is no 'mirroring' option in xcopy. I have 2 suggestions:
1.
you could run xcopy dest source /L > todelete.txt to obtain a list of files which exist in dest but not in source. Then use a for loop to delete these files in dest.
or
2.
Use robocopy which was designed to use the same options as xcopy but has a lot more funtionality. For instance, a /MIR option to mirror one folder to the other. robocopy is included in all Windows versions from Vista on (the Win7 version might run under XP as well - not tested though).
Besides, it is way faster and and and...
Lets say ,
I have xyz.dll in the debug folder, along with resource files folders , de, da ,etc.
F be the project name .
Folder Structure as mentioned below
d:A\B\C\D\E\F\bin\debug
I have to copy the dll and resource file folders from debug folder to C1 folder .
Folder structure as shown below
d:A\B\C1.
available macros are
TargetDir : d:A\B\C\D\E\F\bin\debug
ProjectDir: d:A\B\C\D\E\F\
I tried this but its not working
xcopy $(TargetDir ) $(ProjectDir)........\c1 /R /Y
This copies only the dll not the resources folder .
Any suggestions on how I should do this ?
Use the /S switch to xcopy to include subdirectories recursively
/? is your friend..
C:\>xcopy /?
Copies files and directory trees.
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J]
[/EXCLUDE:file1[+file2][+file3]...]
source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies the size of each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
/B Copies the Symbolic Link itself versus the target of the link.
/J Copies using unbuffered I/O. Recommended for very large files.
The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.
finally I found a way ,
xcopy $(TargetDir).$(ProjectDir)..\..\..\C1 /R /Y /E .
There is an * operators surrounding the dot(.) after the $(TargetDir) ,As its not visible when i post it , I'm mentioning it here .
I am trying to write a Windows Batch file that will allow me to move all directories within a given source directory into a target directory that exists within that source directory.
Obviously my move command with need to only apply to directories and also exclude the target directory from being processed.
Is this possible with a Windows batch command?
Robocopy (present in recent versions of windows or downloadable from the WRK) can do this, just use the /xd switch to exclude the target directory from the copy;
robocopy c:\source\ c:\source\target\ *.* /E /XD c:\source\target\ /move
FOR /d %%i IN (*) DO IF NOT "%%i"=="target" move "%%i" target
That won't work - you'll get an error telling you the target directory is inside the source directory or so, even if you explicitly exclude the target directory. What you can do is move the directories to a temporary location which is not under the source, and then move them into the target.
BTW, using the move command won't let you specify folders to exclude. For that you can use xcopy, but note that it will copy the folders, as opposed to move them. If that matters, you can delete whatever you want afterwards, just make sure you don't delete the target dir, which is in the source dir...
Using robocopy included with Windows 7, I found the /XD option did not prevent the source folder from also being moved.
Solution:
SET MoveDirSource=\\Server\Folder
SET MoveDirDestination=Z:\Folder
FOR /D %%i IN ("%MoveDirSource%\*") DO ROBOCOPY /MOVE /E "%%i" "%MoveDirDestination%\%%~nxi"
This loops through the top level folders and runs robocopy for each.
NB: Robocopy mentioned above using the /move flag will copy the files and then delete them from the source folder rather than moving the files. This may be critical if moving large numbers of files from one location to another on the same disk (because move is virtually instantaneous, while copying is a much slower operation)
On windows batch:
FOR /d %%i IN (MySourceDirectory\*) DO move "%%i" MyTargetDirectory\%%~ni
The above command moves all directories found in MySourceDirectory (/d) to MyTargetDirectory using the original directory name
(~ni) Robocopy's move first does a copy, then delete, so it is slower.
This works for me:
move c:\fromDir\*.* c:\toDir\
I just recently saw that xcopy is deprecated and that Robocopy is recommended.
I tried moving files with it, but couldn't get it to work.
I tried moving files from C:\Downloads\Temp to F:\Temp
Both folders had no files directly under them. Downloads\Temp has about 20 folders, some of which have subfolders, which are eventually filled with files.
With the following syntax, it didn't work:
robocopy C:\Downloads\Temp F:\Temp /move
So I tried giving a wildcard for files:
robocopy C:\Downloads\Temp F:\Temp * /move
Didn't work either. I ended up doing it with xcopy, no problem.
Can someone tell me what I did wrong here?
I'm on Windows Vista Enterprise SP1, as administrator(CMD was also run as administrator)
With the following syntax, it didn't work:
robocopy C:\Downloads\Temp F:\Temp /move
Yes - this says move all files from c:\downloads\temp to f:\temp - only files directly in those directories.
You need the /S switch to say "recursively down the directory stack":
robocopy C:\Downloads\Temp F:\Temp /S /move
Marc