I'm trying to copy the ChromeData subfolder with permissions that may or may not be inside user profiles. so the folder structure is as follows.
-user1
-chromeData
-contacts
-desktop
-user2
-chromeData
-contacts
-desktop
the destination should be like this.
-user1
-ChromeData
-user2
-ChromeData
My code is as follows. It does copy the content in the chromeData folder to the destination, but it does not copy the permissions. Please note that I have used /mir /secfix and /copyall with robocopy. None of them worked. I saw a post saying robocopy does not copy inherited permissions. If this is true I need a workaround.
#echo off
setlocal EnableDelayedExpansion
set Source=F:\DFSroot\Redirected Content\
set Target=H:\Redirected ChromeData\
rem dir /s /ad /b "%Source%*.*" | find /i "\ChromeData" > C:\Temp\dir.txt
for /F "tokens=*" %%a in (C:\Temp\dir.txt) do (
set T1=%%a
call set T2=!T1:%Source%=%Target%!
robocopy "%%a" "!T2!" /copyall
pause
)
UPDATE
Found that permission is being copied for the chromedata folder but not its parent folder.
Use the following command to copy with the ACLs
robocopy "source address" "destination address" *.* /sec
Use the following command to fix an existing tree.
robocopy "source address" "destination address" *.* /secfix /sec
Found this information on this blog
Related
I safe some Files at my Local Drive(Laptop) and also have Files saved at my Network Storage at Work.
I want that both Folders have the same Files, If I create/delete or change an File in one Folder, the other Folder should get Updated when I use the BATCH.
It should use the newest Version on an Document.
So I tried it with ROBOCOPY Folder01 Folder02 /MIR /R:3 /W.20, it worked but only in one Way, from Folder01 to Folder02, so if I created an File in Folder02 and used the Batch, the File got deleted.
Then I tried to copy both Folders into one TEMP Folder and then copy the TEMP-Files to both Folders. I used
ROBOCOPY Folder01 TEMP /XO /E /R:3 /W:20
ROBOCOPY Folder02 TEMP /XO /E /R:3 /W:20
ROBOCOPY TEMP Folder01 /MIR /R:3 /W.20
ROBOCOPY TEMP Folder02 /MIR /R:3 /W.20
this was almost perfect, always the newest Document was used and everything was there, but when I delete a File from Folder01, which still exists in Folder02, it will come back next time I use my BATCH.
Sorry for my English
Greetings, Tobias
Try this solution provided by #Sachadee with Xcopy
:://Synchro.bat
:://SachaDee 2014
#echo off&cls
:: We set Folders to synchonized
set "Folders= C:\HackooTest E:\Backup\Folder1 E:\Backup\Folder2 E:\Backup\Folder3"
for %%a in (%Folders%) do (
for %%b in (%Folders%) do (
if not "%%a"=="%%b" (
set "VAR%%a%%b=%%a %%b"
)
)
)
for /f "tokens=2,3 delims== " %%a in ('set VAR') Do (
echo xcopy "%%a" "%%b" /E /D /C /Y /I
)
pause
S:
cd \newclients
xcopy "s:\clients\*\MER" . /s /d
pause
This is my batch file. In my folder tree we have clients then names folders then MER folder. I want to be able to search the directory for the MER folder and copy that folder along with the client name before it. Is there a way to do this with batch files?
Using if exist should do the thing.
pushd "s:\newclients"
for /f "delims=" %%f in ('dir /b /ad "s:\clients\*"') do (
if exist "s:\clients\%%f\MER\nul" ( xcopy "s:\clients\%%f\MER" "s:\newclients" /s /d )
)
popd
pause
Note: Add a slash if it's to check folder ie. if exist "s:\clients\%%f\MER\" ... or if exist "s:\clients\%%f\MER\nul" ...
To suppress prompt about destination file/folder add /I in xcopy :
/I If in doubt always assume the destination is a folder
e.g. when the destination does not exist.
https://stackoverflow.com/a/33445866/
Following is my command to copy the files in my computer and from my computer to network.
ROBOCOPY "K:\Builds" F:\Builds\ /E /COPY:DAT
ROBOCOPY "E:\" "K:\Shan Khan\" /E /COPY:DAT
How i can make timestamp in destination folder only when copying the file for example
"K:\Builds" when copied to F:\Builds\
F:\Builds\ ---> F:\Builds_26092015
"E:\" when copied to "K:\Shan Khan\Workspace"
"K:\Shan Khan\Workspace"---> "K:\Shan Khan\Workspace_26092015"
Kindly note that K drive is password protected and i manually saved the password while mapping the IP address to K drive.
I tried this lines and it works.
it created the directory in such a way
Fri 06_26_2015
for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
md F:\Builds\"%date:/=_%"
ROBOCOPY "K:\Builds" "F:\Builds\%date:/=_%" /E /COPY:DAT /DCOPY:T
I want to delete files and folder in a directory excluding some file and folder in a bat file.
I need to keep these file, update.bat FolderName.zip FolderName and all other should deleted from the directory,
I wrote the .bat file but seems FolderName also get deleted from directory, rest working fine.
Can anyone tell what wrong with below script?
attrib +r update.bat
attrib +r FolderName.zip
attrib +r FolderName
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
attrib -r update.bat
attrib -r FolderName.zip
attrib -r FolderName
Thanks
Haris
You are misunderstanding how "Read Only" works for folders in Windows. It's not your fault. It's a misleading label. "Read Only" on a folder makes all files within the folder read only, but not the folder itself.
Note
Setting a folder to read-only makes all the files in the folder read-only. It does not affect the folder itself.
My apologies for quoting the Vista documentation, I wasn't able to find a similar page for folders for Windows 7. It is mentioned in the UI though:
How do we work around this?
We are going to set the system attribute as well.
attrib +r update.bat
attrib +r FolderName.zip
attrib +r +s FolderName
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
attrib -r update.bat
attrib -r FolderName.zip
attrib -r -s FolderName
Example utilization:
Before running update, my directory contains the following:
<DIR> FolderName
FolderName.zip
New Bitmap Image.bmp
<DIR> New folder
New Microsoft Word Document.docx
New Text Document (2).txt
New Text Document (3).txt
New Text Document.txt
update.bat
After executing the update.bat, the directory now looks like this:
<DIR> FolderName
FolderName.zip
update.bat
While it is usually used to copy files, with a proper setup robocopy can also handle file/folder removal. All that is needed is an empty folder as source, your folder to clear as target and the /purge switch will remove all files in target not present in source. File and folder retention is handled with /xf (exclude files) and /xd (exclude directories) switches
#echo off
setlocal enableextensions disabledelayedexpansion
set "target=%~1"
if not defined target set "target=%cd%"
set "excludedFiles=update.cmd foldername.zip"
set "excludedFolders=folderName"
2>nul (
for %%a in ("%temp%\%~nx0.%random%%random%%random%.tmp") do (
md "%%~fa"
robocopy "%%~fa" "%target%\." /l /s /e /nocopy /purge /xf %excludedFiles% /xd %excludedFolders%
rmdir /s /q "%%~fa"
)
)
The robocopy command includes a /l switch to only list the files/folders involved in the operation. If everything seems right, remove the /l to perform file/folder removal.
you can try to using TotalCommander with Synchronize Dirs options, make one empty folder for Synchronize.
Using Robocopy to merge two user home directories shares from two different servers to a new server, but can't use /purge to mirror deletes because it will delete the other servers stuff.
I need a way to enumerate the folder names from the users$ share on each server, and add it to both path statements in the command below, so I can purge at the Users subfolder level.
Robocopy command:
robocopy "\CurrentServer1\users$" "F:\Users" /E /B /COPY:DATSOU /R:1 /W:1 /MT /LOG:"C:\RobocopyLogs\MirrorUsers1.txt"
Can a batch or vbscript do that?
Thanks in advance for any help you can provide.
You could merge both source folders into a staging folder, then mirror that staging folder to the destination folder:
mkdir C:\staging
robocopy \\server1\src C:\staging /e /b ...
robocopy \\server2\src C:\staging /e /b ...
robocopy C:\staging C:\dst /mir /b ...
rmdir /s /q C:\staging