Search code examples
batch-filexcopyrobocopy

Batch Script to Copy / Mirror certain files


Firstly I'm newbie so sorry if this is a simple task. I have a folder which contains only PDF files and I need to copy only files which contain certain text [this text varies but the start is always the same] for example

  • test_variablename_datestamp.PDF.
  • testing_variablename_datestamp.PDF.
  • sample_variablename_datestamp.PDF.

I would like to copy any file which starts with test to a test folder, and so testing to testing folder and sample to sample folder. I plan to have this as a script to run every 30 minutes so it only needs to copy if the file has changed [this should reduce the amount of copying it has to do]

I'm new to batch scrip writing but I am trying it out today.

Thanks in advance J


Solution

  • You can use * as a wild card to move the files you need.

    @echo off
    pushd "C:\pdf_files"
    copy test_*.pdf "C:\test_files"
    copy testing_*.pdf "C:\testing_files"
    copy sample_*.pdf "C:\sample_files"
    popd
    

    Obviously, replace the paths with the ones you're using.