Batch file to copy files from one directory to another - windows

I have two code bases of an application. I need to copy all the files in all the directories with .java from the newer code base, to the older (so I can commit it to svn).
How can I write a batch files to do this?

XCOPY /D ?
xcopy c:\olddir\*.java c:\newdir /D /E /Q /Y

If you've lots of different instances of this problem to solve, I've had some success with Apache Ant for this kind of copy/update/backup kind of thing.
There is a bit of a learning curve, though, and it does require you to have a Java runtime environment installed.

I like Robocopy ("Robust File Copy"). It is a command-line directory replication command. It was available as part of the Windows Resource Kit, and is introduced as a standard feature of Windows Vista and Windows Server 2008.

Related

SCCM 2012 to distribute files (not application)

I want to use SCCM 2012 to distribute some files (not application, no executable there).
I know there is a way to create a batch file with xcopy command, and create a package to deploy that batch file to the clients. However, if I use xcopy I cannot leverage the BITS functionality and other benefits from SCCM.
Is this possible?
Hi I can see this is an old post, but I have used SCCM to copy files in the past.
A company I worked for in the past refused to use GP for any file copy (don't get me started) so I had to implement GP files over SCCM.
Here are some examples I used.
xcopy User.bmp "%ProgramData%\Microsoft\User Account Pictures" /c /y /r
REG ADD HKLM\Software\FILE_GP /v Copy_User_image /t REG_sz /d 1.0 /f
timeout 5
if not exist "%windir%\system32\oobe\Info\backgrounds" md "%windir%\system32\oobe\Info\backgrounds"
xcopy backgrounddefault.jpg "%windir%\system32\oobe\Info\backgrounds" /c /y /r
REG ADD HKLM\Software\File_GP /v Backgrounddefault /t REG_sz /d 1.0 /f
timeout 5
I had the script add the Registry key so I could use Application deployment and have the detection method look for the key as well as the file. So if a user deleted the file it would return.
The main reason for me to have the Reg Key was if you wanted to push an updated version of the file I could set the new copy script to push 1.1 to the reg key and have the detection look for that version, then I could retire the 1.0 version.
I found also for short scripts of 1 file of small size without the timeout line it would report failed immediately, if there were larger files I didn't need the timeout. The initial fail does clear after some time without the timeout line.
It should work if you chose your settings right.
In your batch make sure that all the paths and references are relative and never absolute.
Then when you create the deployment there is a point called "Distribution Points" where you can select the deployment options for fast as well as unreliable networks. There you would have to choose "Download content from distribution point and run locally" in both cases. Then your batch would basically copy the files from the CCM cache to the hard drive.
This method should work for packages, for applications I think it would be more difficult because you cannot directly specify deployment options for fast networks there.
Packages are downloaded to the clients with BITS by default. The XCOPY command would copy from CCMCACHE to final destination on the machine.
Not sure if you have tried it or not but if you have deployed any .exe file for application its ask for dependence file in that you mention your required file which need to copy and create a script to copy data from ccmcache to copy the data to destination folder. for this you can get the use of BITS and to check if the file are copied or not you can use a proper detection method.
I used a PowerShell script for this purpose and it works like charm.
Create a new script and change this one liner to your mods:
Copy-Item -Path "\\[NETWORK PATH]" -Destination "[DESTINATION PATH]" -Recurse
Other way around—if need to make a required package—could be to create a new application deployment and run this through PowerShell (ExecutionPolicy ByPass) and manually install from the client side; if you don't want user interaction, make it a required deploy.

Is xcopy used to copy (backup) svn repository?

If it is used what is the difference between svnadmin hotcopy and xcopy? And how can I run xcopy command for each repository in ReposFolder in windows batch file? My assumption is if it is useful to backup svn repository I can just xcopy ReposFolder to backup every repository inside that directory. Thanks in advance for your help.
Yes, you can use xcopy or even better Robocopy to copy the SVN repositories, SVN will still work as usual if retored back. BUT it is always recommended to use the SVN admin copy/load to backup as it is more reliable and backsup all the revisions and if the copy interrupted in between, you will be able to just overwrite the revisions where you left.
Below is the syntax for robocopy. check Robocopy /? for mode options.
robocopy /e c:\repositories \\backupserver\svncopy
Cheers, G

Copying files as administrator in a batch file

So I have a batch file that copies files from one folder to a bunch of different folders.
The purpose of this batch file is to be like a simple installer(Without registry edits) to make it easier for others to use a set of files I am distributing. Because this is being widely distributed, it will need to work on windows operatings systems from XP on. The files need to be moved to the program files of a program (This works), their documents folder(Also works), and the program folder in the all users start menu(Does not work).
So far I have been unsuccessful with xcopy and robocopy as they both tell me "access denied". Also running the batch file with "Run as administrator". If you can think of a more effective way to do what I'm trying to do besides a batch file I am open to ideas.
xcopy /q /y ".\add_ui.bat" "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\My Program\Add.bat"
I'm sure there's some simple trick that I'm missing.
Thanks in advance!
You must have local admin rights to write to that folder and your batch file will need to be ran with elevated permissions (Run As Adminstrator).

A script to automatically delete folders in another folder

I've came across several posts and even code online about .batch files to delete folders and files. However, I am still pretty confused by the myriad amount of information that's on the Internet. Is there a specific way of writing a script that automatically deletes folders that are older than 30 days (the script has to be smart enough to run itself and not be done manually)
I appreciate your help and I am willing to learn here. Thanks!
P.S. I've attached an example of the kind of folders that I would like to delete. As you can see these folders date back to 2008
This will remove the entire directory tree, so use it with coution and remove the echo, if the output is OK:
forfiles /d -30 /c "cmd /c if #isdir==TRUE echo rd /s /q #fname"
Scripts can not run them selves automatically, but the os provides facilities to do that using scheduled tasks. So you need to create yourself a batch file to delete what you need and then add a recurring scheduled task to do the work.
There is no built-in batch command to work only on files with a certain age. But you can download the forfiles tool from Microsoft. It allows to execute commands on files of a certain age only (on the command line).

forfiles *.something mask does not filter output

I'm trying to run a basic forfiles command, but no matter what mask I use it always simply prints the whole content of the directory. Not filtered for *.bat no "is a batch file", just a simple list off all files in C:\
I'm working on a winXPproffesional. What could be the cause?
forfiles /p c:\ /s /m *.bat /c "cmd /c echo #file is a batch file"
Somehow this version uses a different syntax:
FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo #file is a batch file"
works!
The command should work.
Maybe you have a FORFILES.BAT, FORFILES.CMD or bogus copy of FORFILES.EXE in either your current directory or another directory that happens to be in your PATH.
Try running this command from the command line to verify that the correct FORFILES.EXE is executing.
for %F in (forfiles.exe forfiles.bat forfiles.cmd) do #echo %~$path:F
If that is not the problem, then it looks to me like you have a bugged version of FORFILES.
Try using one option at a time to see which, if any of the options work
As a matter of fact, there's no forfiles in Windows XP but there is one in Windows 2003 Server, with the syntax as in your question.
Windows 2000 did have the tool, but only in the form of a resource kit, which had to be downloaded separately. For some reason, the corresponding Technet article doesn't list forfiles as part of the kit, although, as can be derived from this and this article, it must have been there initially. Maybe the guys at Microsoft decided to stop distributing the older version to avoid possible confusion with the newer one.
And yes, it seems like your forfiles copy is the older version, which does have a slightly different syntax, as explained in this post.

Resources