3

I am a novice but trying to create a batch file that reads the folder contents of the source, compares the files to the destination, backs up the matches, and then moves the source files to the destination. I guess in a way the file contents in the source directory works as a mask.

Is there a technique I could use to get this result? I've tried Robocopy and XCopy with close but not what I am looking for. XCopy has an exclude option but that's the opposite of what I need. Any suggestions would be much appreciated.

The set up is like this:

These folders contain this

Parent_folder_new
Folder1        Folder2      Folder3
  File1          File1        File1
  File2          File2        File2
  File3          File3        File3

I have new files to replace the old:

Parent_folder_old
Folder1      Folder2      Folder3
  File2        File1        File1
  File3                     File3

Before the source files overwrite the destination ones I need to backup only the soon-to-be overwritten files.

I've tried an if statement but I don't know where to go after that

Set folder[1]=folder1
Set folder[2]=folder2
Set folder[3]=folder3

for F "tokens=2 delims==" %%f in ('set folder[') do (
     if Parent_folder_new\%%f==Parent_folder_old\%%f
 ::copy results of if statement to Parent_folder_backup\%%f
  )

I hope this clears up somewhat of what I'm trying to do.

Hackoo
  • 18,337
  • 3
  • 40
  • 70
Sid
  • 107
  • 4
  • Please share what you have tried and describe exactly what you have problems with, then we might be able to help you. – aschipfl Mar 29 '16 at 16:00
  • I updated the specifics, i hope this helps – Sid Mar 29 '16 at 21:46
  • 2
    Your approach seems to be a bit unflexible as there might be more than 3 folders in the parent location; is there only one directory level, or is it a deeper tree? if the latter is true, do you want to handle only the first directory level and ignore the deeper lying items? anyway, if I understood it right, you could use `xcopy /L /U` to get a list of files that would be copied (`/L` tells `xcopy` to just list items but not copy any) and use this as the input for a backup job, and then use `xcopy /U` (without the `/L` switch to truly copy this time)... – aschipfl Mar 29 '16 at 22:27

1 Answers1

0

I would use this for copying the files

copy /y C:\path\folder1 C:\destination

and this for moving it

move /y C:\path\folder1 C:\destination

You will have to change the folder1 to any folder you want. I used this to backup my thumbdrives.

echo off
:start
echo What folder/files do you want to copy?
set /p copy=:
echo Is %copy% correct? (Y/N)
echo Note: This must be a directory path.
set /p final=:
if %final% == Y goto desRequest
if %final% == N goto start
:desRequest
echo Destination?
set /p destination=:
echo Is %destination% correct? (Y/N)
set /p finalDes=:
if %finalDes% == Y pause
if %finalDes% == N goto desRequest
echo Copying...
copy /y %copy% %destination%
echo Copied!
pause
cls
goto start

Just copy this into a name.bat file and you are set!

Eternal_Dusk
  • 175
  • 12