4

how to rollback copy of files from SOURCE to DESTINATION? Let me give examples based on Magento (but it does not matter).

When I install a new module, I get a zip file, I extract it in a temporary folder like c:\temp\my_new_module

I have a bunch of directories and files extracted there, from the zip. Some of the directories map Magento directories, some are new directories.

Then I copy files from the main path (c:\temp\my_new_module) to magento root path (c:\magento)

Let's say I test the module few days later, and I don't like it, how can I rollback DESTINATION? ie, how to remove from DESTINATION=c:\magento:

  1. new directories with new files from c:\magento (that were copied from SOURCE)
  2. new files added to existing Magento directories

It means I want to preserve files and folders in DESTINATION that were already there before the copy paste! I don't want to touch anything from SOURCE (neither remove or whatever).

I'm looking for a script to do that (command line), I guess it would compare SOURCE and DESTINATION.

For Each File from SOURCE
    if FILE_EXIST in DESTINATION 
    Then DELETE FILE From DESTINATION
    If DIRECTORY_IS_EMPTY in DESTINATION 
    THEN DELETE DIRECTORY in DESTINATION

(the latter will preserver non-empty directories, ie the one that were created before the copy)

thanks for any help, Rod

3
  • Your question doesn't make sense... because if you just delete my_folder, you end up with the same my_new_folder. So, why are you copy and deleting folders, when you can just delete the folder alright. Maybe you meant you question to mean something... In that case, you need to re-write to be more clear.
    – Sun
    Aug 22, 2016 at 17:15
  • I answered your question but I think you need to modify it to specify correctly what you are trying to accomplish since after reading it you are copying files from one location to another and want to remove the files you COPIED from the source location since those already exist in the new copied over to destination directory but I think you had a typo or two confusing want you are trying to accomplish. Sep 4, 2016 at 6:47
  • my bad, I re-wrote the question
    – Rod
    Oct 28, 2016 at 13:49

1 Answer 1

2

My question is, days after I did that, how can I automate the removal of all Files I have copied?

You can use Robocopy to say look at a [source] directory for all files and subfolders and check recursively against another [destination] directory for the same files that already exist in source.

You can use the options to have it delete files from the source if it finds these same files already exist in the destination (the folder you copy these to) already, and it'll do that recursively but not remove any folders.

You can also use options to have it NOT copy files in the source that are not in the destination directory to NOT copy those over since you will complete the copy operation manually.

You only need to delete FILES from the source recursively that already exist in the destination. You will complete the copy operation of new files from source to destination manually, and only need something to help simplify cleaning of the files in source which have already been copied over manually to the destination.


Robocopy Script

I tested the scenario listed above and it worked just as I explain and just as expected so this method has been tested

@ECHO ON
SET Source=F:\TestSource
SET Destination=F:\TestDest

ROBOCOPY "%Source%" "%Destination%" *.* /S /IS /PURGE /MOV /NOCOPY
GOTO EOF

Further Resources

         /S :: copy Subdirectories, but not empty ones.
    /NOCOPY :: COPY NO file info (useful with /PURGE).
     /PURGE :: delete dest files/dirs that no longer exist in source.
       /MOV :: MOVe files (delete from source after copying).
        /IS :: Include Same files.
1
  • sorry my bad, my question was not clear. I want to rollback DESTINATION to what it was before. I have updated my question. any other suggestiion?
    – Rod
    Oct 28, 2016 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .