Avatar of westone
westone
Flag for United States of America

asked on 

RoboCopy error 1921

Hi,
I am attempting to use the attached script to backup the Users folder on a Vista Home Premium machine. The script fails however when it gets to the first users Application Data folder. I will try to explain this clearly: It gets stuck in a loop where it keeps adding "Application Data" as a subfolder to the current folder (which is the actual Application Data folder), and trying to look for files that need copying in that non-existant folder. So in the first loop it is looking for "Users\Bob\Application Data\Application Data", then in the next loop it is looking for  "Users\Bob\Application Data\Application Data\Application Data". Eventually the folder name gets so long it fails with Error 1921: The name of the file cannot be resolved by the system.

The attached images from the Command window when the script runs may more clearly show what is happening. Why is this occurring and how can I remedy it?

Thanks,
Bill


@echo off
setlocal
 
set dest=j:\backups
 
set root=%allusersprofile%\..
set exclude=/C:"All Users" /C:"Default User" /C:"LocalService" /C:"NetworkService"
 
for /F "tokens=*" %%G in ('dir "%root%" /A:D /B^| findstr /I /V %exclude%') do (
 robocopy "%root%\%%G" "%dest%\%%G" /ZB /MIR
)

Open in new window

Image1.doc
Image2.doc
Windows Batch

Avatar of undefined
Last Comment
westone

8/22/2022 - Mon