Robocopy/MOVE: Attempt to Delete Non-Empty Folders?

Abstract: Resolve Robocopy move errors caused by locked files or permission issues preventing source folder deletion.

Created: 2026-10-20 by

The "Attempt to delete a directory or file that is not empty" error occurs when Robocopy fails to clear the source folder after a move operation. This usually happens due to permission issues, open files, or insufficient privileges. To resolve it, ensure no files are locked, run the command as an administrator, and verify that the destination copy succeeded before deletion.

Understanding the Error Cause

Robocopy is a powerful command-line utility designed for robust file copying and moving. When you use the /MOVE switch, Robocopy performs two distinct actions: it copies all files and folders from the source to the destination, and then it attempts to delete the original source content. The error message indicates that the second step has failed. Specifically, the system cannot remove the source directory because it still contains items that the current process does not have permission to delete, or which are currently in use by another application. This behavior is distinct from simple copying. If you were using only /COPYALL, the source would remain untouched. However, /MOVE implies a transfer of ownership and physical location. The failure at the deletion stage suggests that while the data was successfully written to the new location, the cleanup phase encountered an obstacle. Common culprits include residual read-only attributes on files, active locks from antivirus software scanning the newly copied files, or user account control restrictions preventing the deletion of system-protected directories.

Permissions and Ownership Issues

One of the most frequent causes involves access control lists (ACLs). If the source folder contains subdirectories with specific permissions that differ from your current user context, Robocopy might succeed in copying the files but fail to delete the empty shell of the folder structure afterward. Additionally, if the source is located on a network drive with restrictive policies, the network session might drop during the large file transfer, leaving orphaned files that prevent folder deletion. Ensuring that you have full control over both the source and destination paths is critical. You can check this by right-clicking the folder, selecting Properties, and navigating to the Security tab to verify your user account has "Full Control."

File Locks and Antivirus Interference

Another significant factor is file locking. If any file within the source directory is open in another program, such as a text editor, media player, or even an index service like Windows Search, the operating system will block its deletion. Furthermore, real-time antivirus protection often scans files immediately after they are created or modified. If the antivirus engine holds a lock on a newly copied file for a brief period, Robocopy may attempt to delete the parent folder before the scan completes, resulting in the error. Disabling real-time protection temporarily or adding an exclusion for the source and destination folders can help isolate this issue.

Step-by-Step Resolution Guide

To effectively resolve this error and complete your file move operation, follow these diagnostic and corrective steps. These methods address the most common technical barriers without requiring third-party tools.
  1. Run as Administrator: Always execute the Command Prompt or PowerShell window with elevated privileges. Right-click the start menu icon and select "Terminal (Admin)" or "Command Prompt (Admin)." This ensures Robocopy has the highest level of authority to bypass standard permission checks during the deletion phase.
  2. Close Open Applications: Before running the command, close all applications that might be accessing files in the source directory. Pay special attention to background processes like cloud sync clients (OneDrive, Dropbox) or email clients that might be indexing the folder.
  3. Verify Destination Integrity: Manually check the destination folder to ensure all files were copied correctly. If the copy failed partially, Robocopy might behave unpredictably during the move phase. It is safer to retry the copy first before attempting a move.
  4. Use /E and /MOVE Together: Ensure your command includes the /E switch to copy subdirectories, including empty ones, along with /MOVE. The correct syntax typically looks like: robocopy "SourcePath" "DestPath" /MOVE /E.
  5. Check for Read-Only Attributes: Run the command attrib -R "SourcePath\*.*" /S /D before the move. This removes read-only flags that can sometimes block deletion operations, although Robocopy usually handles this automatically.
For more details on optimizing Robocopy performance and understanding output logs, you might find it helpful to review How to Measure Robocopy's Copy Speed and Files Skipped/Copied?. Understanding the log output can help you identify exactly which file caused the deletion failure.

Alternative Approaches

If Robocopy continues to fail despite these steps, consider alternative strategies. You can perform the operation in two separate steps: first, use /COPYALL to copy all files and attributes without deleting the source. Once verified, manually delete the source folder using File Explorer or the rmdir /s /q command. This separation allows you to diagnose whether the issue lies in the copying process or the deletion process. Another option is to use PowerShell cmdlets like Copy-Item followed by Remove-Item. While less efficient for massive datasets than Robocopy, PowerShell provides better error handling and logging capabilities through its object-oriented pipeline. For recursive copying tasks where moves are not strictly necessary, refer to How to Use Robocopy for Recursive File Copying in Tech Support to learn how to optimize the copy phase alone.

Troubleshooting Specific Scenarios

In some cases, the error persists due to symbolic links or junction points. If your source folder contains shortcuts to other locations, Robocopy may struggle to resolve them during deletion. Inspect the source directory for any symlinks using the dir /al command in the command prompt. Removing these links before the move operation can prevent confusion in the deletion routine. Additionally, if you are moving data to or from a portable USB drive, be aware of potential filesystem inconsistencies. As noted in discussions about portable drives, hidden system files can interfere with operations. See Unaccountably, Folder Robocopied to Portable USB Drive on Laptop PC Becomes System + Hidden - What to Do? for insights on handling hidden system attributes that might block standard deletion commands.

Frequently Asked Questions

Why does Robocopy delete files but leave folders?

This happens when individual files are deleted successfully, but the parent folder remains because it contains hidden system files or has restricted permissions. Check for hidden files using dir /ah and ensure your user account has full control over the root directory.

Can I recover files if the move fails halfway?

If the move fails, the destination folder should contain the copied files, while the source folder remains intact. Verify the destination integrity manually. If files are missing, re-run the command with the /MIR switch instead of /MOVE to mirror the directory structure without immediate deletion risks.

Does antivirus software cause this error?

Yes, real-time scanning can lock files immediately after they are copied, preventing Robocopy from deleting the source. Temporarily disabling real-time protection or adding exclusions for the source and destination folders can resolve this interference.

How do I force delete a non-empty folder via command line?

You can use the rmdir /s /q command to force delete a folder and its contents silently. However, this bypasses Robocopy's safety checks and should only be used if you are certain the data has been safely backed up elsewhere.

What is the difference between /MOVE and /MIR?

The /MOVE switch copies files and then deletes the source, preserving the directory structure. The /MIR switch mirrors the source to the destination, meaning it also deletes files in the destination that no longer exist in the source. Use /MOVE for transfers and /MIR for backups.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More