I have some files in my project that are used for unit testing, and than files that will be used in the actual release.
Currently have 'Copy to output directory' copy always turned on.
Is there a more direct way to send only certain files to the 'Release' directory and others to the 'Debug' directory when building?
I ended using the command line build events property in the MAIN/Solution project.
yourproject > properties > build events
Pre build event command line
First i cleaned out the directory
rd /s /q "$(TargetDir)Configs"
Post-build event command line
Next on Debug, copy all.
And on Release, del everyting that was for testing.
if "$(ConfigurationName)"=="Debug" (
xcopy "$(ProjectDir)Configs\*.*" "$(TargetDir)Configs\" /y
del "$(TargetDir)Configs\_notes.*"
)
if "$(ConfigurationName)"=="Release" (
xcopy "$(ProjectDir)Configs\*.*" "$(TargetDir)Configs\" /y
del "$(TargetDir)Configs\test*.*"
del "$(TargetDir)Configs\_notes.*"
)
IN the test Project, used the same PRE command.
Had to change the POST command a little.
if "$(ConfigurationName)"=="Debug" (
xcopy "$(SolutionDir)$(SolutionName)\Configs\*.*" "$(TargetDir)Configs\" /y
del "$(TargetDir)Configs\_notes.*"
)
if "$(ConfigurationName)"=="Release" (
xcopy "$(SolutionDir)$(SolutionName)\Configs\*.*" "$(TargetDir)Configs\" /y
del "$(TargetDir)Configs\test*.*"
del "$(TargetDir)Configs\_notes.*"
)
I think this could be slimmed down, but its working.
my Xcopy fails to execute properly after I compile my project.
xcopy "$(SolutionDir)LuaModules\*.*" "$(TargetDir)Modules\" /S /H /Y /C
You have unneeded slash after /S.
$(SolutionDir) gives the directory where the solution is in, but the project ($ProjectDir) gives the folder of your files. I had to use that instead
need help regarding delete task in nant or command which can be used in nant build file.
here is the requirement, i have multiple files and folders in a root folder.
i need to delete only folders but not files..
Any idea how to do this.
Blockquote
EX : ROOT
-a.txt
-b.txt
-Folder1
-Folder2
after deletion, it should be
Blockquote
EX: ROOT-
-a.txt
-b.txt
Thanks in advance.
for /d %%a in ("c:\some\root\*") do echo rmdir /s /q "%%~fa"
For each folder inside the indicated path, matching the indicated mask, remove the folder
Delete operations are echoed to console. If the output is correct, remove the echo command to execute the rmdir commands.
To include it in a build file, and avoid problems with quoting, it is better to create a batch file to contain the command and call this batch file. That way, the batch file will be something like
#echo off
if "%~1"=="" exit /b 1
for /d %%a in ("%~1\*") do echo rmdir /s /q "%%~fa"
With the path to the folder to clean passed as argument
Then, the exec task will be something like
<exec program="cmd.exe" commandline="/c theBatchFile.cmd" workingdir="${project.batchFiles}" output="e:\my.txt">
<arg value="${project.rootFolder}" />
</exec>
The variables will need to be defined pointing to
${project.batchFiles} = where the batch file is located
${project.rootFolder} = the folder that needs to be cleaned
So, the task will call cmd.exe to process the batch file, passing the folder as argument to the batch.
used the above suggustions and found it out :
Code :
<echo file="CleanFolders.bat">for /d %%a in ("${dir}\subdir\*") do rmdir /s /q "%%~fa</echo>
<exec program="CleanFolders.bat"/>
I have a folder: C:\Folder1
I want to copy all the contents of Folder1 to another location, D:\Folder2
How do I do this using a batch file?
xcopy.exe is the solution here. It's built into Windows.
xcopy /s c:\Folder1 d:\Folder2
You can find more options at http://www.computerhope.com/xcopyhlp.htm
If you have robocopy,
robocopy C:\Folder1 D:\Folder2 /COPYALL /E
otherwise,
xcopy /e /v C:\Folder1 D:\Folder2
I see a lot of answers suggesting the use of xcopy.
But this is unnecessary. As the question clearly mentions that the author wants the content in the folder not the folder itself to be copied in this case we can do
copy "C:\Folder1\*.*" "D:\Folder2"
Thats all xcopy can be used for if any subdirectory exists in C:\Folder1
if you want remove the message that tells if the destination is a file or folder you just add a slash:
xcopy /s c:\Folder1 d:\Folder2\
RoboCopy did not work for me, and there are some good solutions here, but none explained the XCopy switches and what they do. Also you need quotes in case your path has spaces in it.
xcopy /i /e "C:\temp\folder 1" "C:\temp\folder 2"
Here is the documentation from Microsoft:
XCopy MS Documentation
/s: Specifies to include subdirectories. Excludes empty subdirectories
/e: Copies all subdirectories, even if they are empty
/i: specifies the destination is a folder (Otherwise it prompts you)
Here's a solution with robocopy which copies the content of Folder1 into Folder2 going trough all subdirectories and automatically overwriting the files with the same name:
robocopy C:\Folder1 C:\Folder2 /COPYALL /E /IS /IT
Here:
/COPYALL copies all file information
/E copies subdirectories including empty directories
/IS includes the same files
/IT includes modified files with the same name
For more parameters see the official documentation: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
Note: it can be necessary to run the command as administrator, because of the argument /COPYALL. If you can't: just get rid of it.
#echo off
::Ask
echo Your Source Path:
set INPUT1=
set /P INPUT1=Type input: %=%
echo Your Destination Path:
set INPUT2=
set /P INPUT2=Type input: %=%
xcopy %INPUT1% %INPUT2% /y /s
On my PC, xcopy and robocopy need also the path to them, i.e. C:\Windows\System32\xcopy.exe
That's why I use simply "copy":
copy /y ....\Folder1\File.txt ....\Folder2\
#echo off
xcopy /s C:\yourfile C:\anotherfile\
This is how it is done!
Simple, right?
FYI...if you use TortoiseSVN and you want to create a simple batch file to xcopy (or directory mirror) entire repositories into a "safe" location on a periodic basis, then this is the specific code that you might want to use. It copies over the hidden directories/files, maintains read-only attributes, and all subdirectories and best of all, doesn't prompt for input. Just make sure that you assign folder1 (safe repo) and folder2 (usable repo) correctly.
#echo off
echo "Setting variables..."
set folder1="Z:\Path\To\Backup\Repo\Directory"
set folder2="\\Path\To\Usable\Repo\Directory"
echo "Removing sandbox version..."
IF EXIST %folder1% (
rmdir %folder1% /s /q
)
echo "Copying official repository into backup location..."
xcopy /e /i /v /h /k %folder2% %folder1%
And, that's it folks!
Add to your scheduled tasks and never look back.
I have written a .bat file to copy and paste file to a temporary folder and make it zip and transfer into a smb mount point,
Hope this would help,
#echo off
if not exist "C:\Temp Backup\" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
if not exist "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP"
if not exist "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
xcopy /s/e/q "C:\Source" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
"C:\Program Files (x86)\WinRAR\WinRAR.exe" a "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP\ZIP_Backup_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.rar" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\TELIUM"
"C:\Program Files (x86)\WinRAR\WinRAR.exe" a "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP\ZIP_Backup_Log_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.rar" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
NET USE \\IP\IPC$ /u:IP\username password
ROBOCOPY "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP" "\\IP\Backup Folder" /z /MIR /unilog+:"C:\backup_log_%date:~-4,4%%date:~-10,2%%date:~-7,2%.log"
NET USE \\172.20.10.103\IPC$ /D
RMDIR /S /Q "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
#echo off
:: variables
echo Backing up file
set /P source=Enter source folder:
set /P destination=Enter Destination folder:
set xcopy=xcopy /S/E/V/Q/F/H/I/N
%xcopy% %source% %destination%
echo files will be copy press enter to proceed
pause
I am trying to delete files in my $(TargetDir) within visual studio before building a project.
How do you have to format command line to get around this problem I am getting below?
Try
cd $(TargetDir)
del *.tif
As jvenema pointed out, your $(TargetDir) is expanding into a path containing spaces in the folder names which is breaking the delete command.
I ended up using rd /s /q "$(TargetDir)" to clean out the directory. As far as I know it is working.
Try adding quotes around the directory.
You have to write del "$(TargetDir)*.tif" because of spaces in directory path.
Old question but a couple of things:
del "$(TargetDir)*.tif" /q
1) /q is for quiet. Otherwise, del cmd prompts "... Are you sure (Y/N)?" which the build does not like.
2) As many have pointed out, "" around the targetDir for possible space in the target directory.
For DOTNET Core, your quotes need to be escaped, like this:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="del "$(ProjectDir)wwwroot\_framework\*.*" /q" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy "$(ProjectDir)..\Client\bin\Debug\net5.0\wwwroot\_framework\*.*" "$(ProjectDir)wwwroot\_framework\"" />
</Target>
wmic process where name='chromedriver.exe' delete