#ECHO OFF
SET driveLetter=%~d0
FOR /R %%x IN (*.pst) DO (
ROBOCOPY %%x %driveLetter%\%%x /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
)
PAUSE
EXIT
I can't get this working. What I want to do is search the user folder (incl. subfolders) for any .pst files and then copy these to a flash drive.
Pretty simple actually just use xcopy:
xcopy c:\users\%username%\*.pst F:\ /e
(replace F:/ with drive location if its not F).
#ECHO OFF
SET driveLetter=%~d0
ROBOCOPY %USERPROFILE% %driveLetter%\Outlook *.pst /S /COPYALL /ZB /XJ /MT:20 /R:2 /W:5
PAUSE
EXIT
Solution. Thanks to everybody.
Related
I've made this script (minus all my ECHO for your readability) to backup certain user folders to an external device. It's working flawlessly, but I'm wondering if anyone has any ideas as to how I could simplify it (eg. more 'clever').
I'm new to this site and coding. Please bear with me!
All help appreciated.
#ECHO OFF
SET driveLetter=%~d0
:CHOOSE
SET /P CHOOSE=Are you sure you want to continue [Y/N]?
IF /I "%CHOOSE%" == "Y" GOTO :chooseYes
IF /I "%CHOOSE%" == "N" GOTO :chooseNo
GOTO :CHOOSE
:chooseYes
MKDIR %driveLetter%\Desktop
MKDIR %driveLetter%\Documents
MKDIR %driveLetter%\Favorites
MKDIR %driveLetter%\Pictures
MKDIR %driveLetter%\Downloads
TIMEOUT /T 1 /NOBREAK >NUL
ROBOCOPY %USERPROFILE%\Desktop\ %driveLetter%\Desktop /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Documents\ %driveLetter%\Documents /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Favorites\ %driveLetter%\Favorites /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Pictures\ %driveLetter%\Pictures /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
ROBOCOPY %USERPROFILE%\Downloads\ %driveLetter%\Downloads /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
:chooseNo
TIMEOUT /T 3 /NOBREAK >NUL
Best regards.
If possible, don't repeat yourself
:chooseYes
for %%a in ( Desktop Documents Favorites Pictured Downloads ) do (
robocopy "%userprofile%\%%a" "%driveLetter%\%%a" /E /COPYALL /ZB /MT:20 /XJ /R:2 /W:5
)
CLEANMGR /C: /SAGERUN:65535 /SETUP
TIMEOUT /T 1 /NOBREAK >NUL
DEFRAG /C /H /V /W
PAUSE
EXIT
note: the mkdir has been supressed as the robocopy command will create the target folder
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
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
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
Well, it kind of does but skips one level I think. So, here's folder structure I have (Windows 2008 R2 SP2 standard):
ClientA
|_ClientAfolder1
|_ClientAfolder2
ClientB
|_ClientBfolder1
|_ClientBfolder2
And so forth...
Here's the script I'm using:
for /f "delims=" %%a in ('type "folderlist.txt" ') do robocopy "%%a" "Z:\temp\test" /E /xo /fft /COPYALL /r:0 /w:0
My folderlist.txt looks like this:
f:\ClientA\ClientAfolder1
f:\ClientA\ClientAfolder2
f:\ClientB\ClientBfolder1
f:\ClientB\ClientBfolder2
And after executing the script, my folder structure becomes like this:
ClientAfolder1
ClientAfolder2
ClientBfolder1
ClientBfolder2
So, it skips creating parent folders which are ClientA and ClientB. What am I doing wrong?
Thank you for any help.
for /f "usebackq delims=" %%a in ("folderlist.txt") do (
robocopy "%%a" "Z:\temp\test%%~pnxa" /E /xo /fft /COPYALL /r:0 /w:0
)