0

I'm using robocopy in a batch script to back up all of my files onto an external drive, but I want to exclude any folders that contain (directly) a file called ".nosync", so I can avoid backing up several folders that have gigabytes of data that doesn't need to be backed up. I can't figure out how to do this though.

I tried:

robocopy <source> <dest> /mir /xd ".nosync\.."

But robocopy doesn't appear to follow the relative path. Is there a way to do this, or another utility I can use to mirror changed files to another drive?

1
  • 1
    /xd excludes Directories, /xf excludes files. But you want to exclude Directories that have a file called ".nosync". Don't think robocopy can natively do that. You would have to create a list of the folders that have such files with a script or manually and add them to a exclusion list... Jul 17, 2021 at 23:59

1 Answer 1

1

I tested this and it worked for me:

@echo off
echo.
set /p "Source=Please specify the source folder: "
echo.
set /p "Destination=Please specify the destination folder: "
echo.

set "Source=%Source:"=%"
set "Destination=%Destination:"=%"

pushd "%Source%"

for /f "delims=" %%a in ('dir /b /s /a ^|find /i ".nosync"') do echo %%~dpa>>"%~dp0nocopy.txt"

popd

xcopy "%Source%" "%Destination%" /e /h /r /exclude:nocopy.txt
del /q nocopy.txt
0

You must log in to answer this question.

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