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
Related
#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.
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
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
)
Here is my folder hierarchy:
[Numbers]
[Numbers/12545]
[Numbers/12545/dev]
[Numbers/12545/prod]
[Numbers/32445]
[Numbers/32445/dev]
[Numbers/32445/prod]
...
[Numbers/.....]
[Numbers/...../dev]
[Numbers/...../prod]
I want to copy some text files under the only "[Numbers/...../dev]" folders. How should i do?
I tried the below code and it's not work because it coppies under the all subfolders.
for /r %NUMBER_DIRS% %%d in (.) do (
copy %PROJECT_INPUTS%\*.txt "%%d"
)
Thanks.
Try this:
for /d /r "%NUMBER_DIRS%" %%d in (*DEV) do copy "%PROJECT_INPUTS%\*.txt" "%%~d\*.txt"
#ECHO OFF
SETLOCAL
FOR /f "delims=" %%i IN (
'dir /s /b /a:d "\numbers" ^| findstr /i /e "\dev"'
) do ECHO COPY %PROJECT_INPUTS%\*.txt "%%i\"
This will report what the batch PROPOSES to do. Remove the ECHO keyword before the COPY to execute the copy.
Note : you may need to add /y to the copy options if you want to OVERWRITE an existing file in the destination directories.
I presume that you're copying FROM %PROJECT_INPUTS% TO many ...\dev directories.