So I have been searching around for the answer here and am not able to find it. I'm not by any means well-versed with coding these sorts of things so excuse my noobishness.
So I am trying to create a simple batch file for deployment with a backup device for the end user to double-click and copy their profile folder to the backup media.
I am not certain if xcopy or robocopy is the best solution for this, but coming from server administration I am more familiar with robocopy. The copy utility I'm using isn't necessarily the problem, however.
What I have:
robocopy D:\%USERPROFILE% <destination> /e /copyall
While the source resolves to the user profile without issue, I have not been able to derive a variable for the destination that could account for the possibility of different from letters, which I don't think is possible. Is there a variable that sets the destination as the location from where the batch file is launched?
Thank you for the help!
Is there a variable that sets the destination as the location from
where the batch file is launched?
yes, there is:
echo %~dp0
this gives you Drive and Path of your batchfile. For more ~.modifiers see call /?
Related
I recently started using Google Drive as a corporate account to backup 10,000+ files.
Once I uploaded everything to G:\My Drive\ with taking 3 days.
Now for the operation, I would like to copy only updated files so I created batch file like following.
set TODAY=%date:~0,4%%date:~5,2%%date:~8,2%
set time2=%time: =0%
set TIME=%time2:~0,2%%time2:~3,2%%time2:~6,2%
set LOGFILEPATH=C:\TEMP\%TODAY%_%TIME%.txt
xcopy Z:\ORIGINAL G:\My Drive\BACKUP /D /S /R /Y /I /K /C /F /H
>>%LOGFILEPATH%
It works for other folders like D drive (internal Hard disk drive) however, if you pointed to G drive (Google virtual drive??) then it does not work. i.e. the batch file does not produce any output.
Do you know any command or tools helping this situation?
Again, I want to copy only updated files to Google drive from internal hard disk drive with all the sub directory etc keeping same shape.
Thank you team,
Kaz
I found the following software resolve the issue.
I am not sure why XCOPY didn't work but the following software works perfectly even on Google drive.
[link]http://synchronicity.sourceforge.net/
if some of you achieved another way please let me know.
Firstly, Google drive is referenced with spaces here and secondly, include /M for incremental backup at the source destination side, below is the command skeleton:
XCopy /M [source loc]\*.* G:\"My Drive"\ShareDir /Y
Where, G: is Google Drive, /M will only picks up files that are new or changed & /Y will suppress prompt
Alternatively, use can use below command as well for incremental backup of entire directory:
ROBOCOPY [source location]\ShareDir G:\\"My Drive"\\ShareDir /MIR
Where, /MIR option will mirror the directory as it is (it takes care of the deleted or renamed files/directories as well). Note the use of double slashes.
It works for me; I keep my songs updated to my Google Drive, which I access through a Cloud Music Player.
I'm trying to write a batch file in Window 10 that will copy a folder to overwrite the C:\Windows\System32\GroupPolicy folder. So I do
xcopy /y /e C:\Backup\GroupPolicy %systemroot%\system32\
and it says it copied all the files. But if I check the group policy using gpedit, my changes aren't there. But if I select the C:\Backup\GroupPolicy folder in the file explorer and use ctrl+c and then go to c:\Windows\System32 and do ctrl+v and say yes to the prompt to overwrite the files, when I check gpedit, my changes are there now. When I do it through the GUI, I do get a prompt saying I need admin permissions to copy the folder, so I'm wondering if xcopy is not being given proper admin permissions even though I'm running it from an administrative command prompt.
Not sure what exactly you mean when you say "my changes aren't there".
If your ACL information is missing, then I think you're missing a switch:
/O Copies file ownership and ACL information.
You might also be hitting 32/64 bit environment problems and actually be looking for C:\Windows\SysWOW64.
I found out that the issue was related to permissions. xcopy has some flags like /o /k /r /h that also copy the metadata of the file. Tried that and got permission denied. Then I found that I could use robocopy instead with the /copy:DATSO (/copyall also gave a permission denied error) flag and that worked.
I'm looking to do a mass update on a large number of computers and would like to create a simple script that i can just click and run to complete the work much quicker.
I've never tackled anything like this before so im not really sure where to start.
The goal of the script is to take the files which i will be moving from a drive to each laptop, open cmd.exe execute a command and then run the installer that is generated from it. Any advice or pointers on where i can start would be greatly appreciated.
I can't comment yet so --
As other users have mentioned powershell would be a better alternative to C. Or you could use a batch file.
#echo off
XCOPY <source path> <destination path> /f /-y
start <your program.exe>
When copying it would display the locations it's copying to and from(/f), as well as as for confirmation for overwrites(/-y).
More switches can be seen here for the copy command.
I have a batch file, and i need to move a folder from one directory to another.
I can do that no problem. But, im hitting a problem after that.
The folder i just moved is created at run time, then moved to the final destination folder where it needs to remain, unless the user decides to delete it.
So, if the user runs the batch file a second time, when it tries to move the run time folder, there is already the old version of the folder at the destination and it gives a "permission denied" error.
So my question is, what is the best way to overwrite the contents of a folder from a batch file?
Right now i am just using the move command. Which works fine for overwriting regular files, but it cannot overwrite folders apparently.
Thanks.
Would suggest to use either xcopy or robocopy for Overwriting folders
Xcopy /E /Y would Overwrite folder ,
please find More options Xcopy /?
Please note that i have mentioned this options only to overwrite and not to move folder.
I am having a pdf storage folder on network in which all users used to store their all files for sharing each other . Now I need to copy all those files from that folder to another folder which is on same network but on different server.
Use xcopy and pass in the UNC path of the source and destination. For help on xcopy, run:
xcopy /?
Could you be more precise regarding your OSes, because i think that the answers may vary greatly depending on it.
If it's a windows box, i'd recommend the use of robocopy, which can handle retries, mirroring, speed capping and much more. You can find it here
Use robocopy.exe available here
example:
robocopy \\server1\c$\sourcedir \\server2\backup\server1 /MIR
You will run into problems if any network files are in use at the time of the copy. Make sure you talk with your network administrator and managers to arrange a time that users can leave that directory alone so that your copy will complete without any exceptions.