FreeDOS XCOPY: Tree Copies, Switch Semantics, and Verification
Build predictable FreeDOS XCOPY workflows by choosing tree and attribute switches explicitly, controlling overwrites, and checking copy results.
FreeDOS XCOPY copies files and directory trees, filling the gap between the shell’s simple COPY command and a full backup tool. Its switches determine whether empty directories are included, whether hidden or system files are copied, whether existing files are overwritten, and whether source Archive bits are changed. A correct command is therefore a policy decision, not just a longer spelling of COPY. First inspect the installed XCOPY help and version, then test the exact command against a disposable source tree and destination.
Choose the copy scope
The FreeDOS XCOPY documentation defines the command as XCOPY source [destination] [/switches]. The source can be a directory and/or filename pattern. Destination may be a path or a target name. If multiple files are copied and the destination directory does not exist, /I tells XCOPY to assume the destination is a directory instead of prompting for interpretation.
/S copies subdirectories that contain files but skips empty directories. /E includes empty subdirectories as well. /T creates a directory tree without copying files; adding /E includes empty directories in that tree. Those switches solve different tasks. For a full source tree, /S /E communicates that both populated and empty directories are expected. For a skeleton layout, /T is the appropriate starting point, not a copy with all files removed afterward.
Use rooted paths and a dedicated staging destination. A source such as C:\DATA and a destination such as D:\STAGE make the data flow visible. A relative destination can depend on the current drive and directory, and DOS remembers a current directory per drive. Print CD and the intended source/destination before an automated copy begins.
Attribute and archive-bit switches
/H includes Hidden and System files as well as ordinary files. This is important for a system backup or a faithful migration, but it can also copy files that were deliberately omitted from a normal listing. Enumerate the source with attributes visible before using /H. A destination that already has a file with the same name may be overwritten depending on the overwrite policy.
/A copies only files with the Archive attribute set and leaves the source bit unchanged. /M also selects files with Archive set but clears that source bit after copying. That makes /M an incremental-backup convention, not just a performance switch. If the destination copy was not independently verified, clearing source bits can cause a future incremental run to overlook data that was never safely backed up. Use /A when you want to select changed files without modifying source metadata; only use /M when the backup workflow deliberately owns the Archive-bit lifecycle.
Archive-bit workflows have race conditions: an application may modify a file during the copy, or the copy may fail after some files have already been processed. Keep a manifest of what XCOPY reported, inspect its error output, compare the resulting destination, and do not treat a cleared attribute as evidence that a valid backup exists. FAT attributes are metadata flags, not a durable job database.
Overwrite behavior and prompts
FreeDOS XCOPY provides /Y to suppress overwrite confirmation and overwrite existing destinations, /N to suppress the prompt and skip existing files, and /-Y to request confirmation. The COPYCMD environment variable can preset overwrite behavior for COPY and XCOPY, so the same command line may behave differently under a different environment. Before a script runs, inspect the value with SET COPYCMD and make the intended behavior explicit.
For a human-reviewed first run, use /-Y when overwriting existing files would be consequential, or choose a clean destination directory. Do not use /Y simply to make a script quiet. It removes an important opportunity to notice that the source and destination paths were reversed or that a valuable file already exists. /N is not “no overwrite warning but still update”; it skips existing files, which can leave an old and new tree mixed together.
If the command is intended to replace a staging tree, make the replacement sequence explicit: create a new empty versioned destination, copy into it, verify the result, then change which copy the application uses. Do not first delete the only good destination and then hope that the new copy completes.
Verification and error continuation
/V asks XCOPY to verify each new file. This is useful for detecting certain write or read-back errors during copying, but it does not replace an independent comparison or checksum. It cannot establish that the source was correct, authenticate the source, or guarantee persistence through a power failure. Where the source is available after the copy, compare critical files with FC /B and validate publisher checksums for downloaded software.
/C tells XCOPY to continue even when errors occur. This can be useful when gathering a best-effort copy from damaged media, but it means a command can produce a partially populated destination while continuing. Do not interpret a final prompt or the existence of the target directory as complete success. Preserve output, inspect the utility’s exit code, and maintain a list of skipped or failed files.
FreeDOS XCOPY documents distinct return codes for success, missing source, missing path, access denied, write fault, read fault, and insufficient disk space, with an implementation note about an insufficient-memory code. Check the installed version’s manual because not all errors are necessarily representable in every build. DOS IF ERRORLEVEL n is a greater-than-or-equal comparison, so check higher numbers before lower ones in batch scripts.
A cautious tree-copy example
For a test where both populated and empty directories matter, hidden/system files should be included, and the destination is new:
XCOPY C:\DATA D:\STAGE /S /E /H /V /I /-Y
This command should not be run until D:\STAGE is confirmed to be the intended destination and C:\DATA the intended source. /-Y keeps overwrite prompts if a collision exists; if the destination is known to be empty, it should not need them. On the first run, omit /C so an error does not silently become a partial-success workflow. Capture the full output and check the exit code before declaring completion.
For a skeleton only:
XCOPY C:\PROJECT D:\EMPTY-TREE /T /E /I
/T /E creates the directory layout, including empty subdirectories, without copying the files. Verify the resulting tree by listing both source and destination before using it. The syntax is based on the FreeDOS 1.9 project documentation; check XCOPY /? on the installed system because bundled versions can differ.
Long filenames and legacy constraints
DOS systems commonly use 8.3 names, and long-filename support depends on the kernel, DOSLFN, filesystem, and application. Do not assume that an XCOPY build preserves every long name, timestamp, or attribute on every target. The FreeDOS upstream documentation describes the program’s switches and version, but actual compatibility should be tested with representative long names and metadata on the exact deployment stack.
For a migration, create test fixtures that include an 8.3 name, a long name if supported, hidden and system attributes, a read-only destination collision, an empty directory, a nested directory, and a zero-length file. Copy the fixture, compare contents, inspect attributes, and inspect names on both ends. If preservation requirements exceed the tool’s documented behavior, use an archive format or a specialized migration tool with explicit metadata guarantees.
XCOPY is also not a complete backup product. It does not by itself create a consistent snapshot of files being modified, preserve every filesystem feature, produce a cryptographically protected manifest, or guarantee a restore. For databases and active applications, use their supported export or quiescing process before copying. For a system disk, prefer an image-level backup that preserves partition and boot metadata in addition to ordinary files.
Common operational mistakes
The most common mistake is ambiguous destination interpretation. If the target does not exist and the source expands to one file, the command may interpret the destination as a filename; with multiple files, /I can force directory treatment. Create the destination directory first when that makes intent clearer. Another mistake is forgetting that /S omits empty directories; if application behavior depends on an empty directory existing, add /E or use /T /E for a skeleton.
Using /M on a source tree without recording the original Archive state can also disrupt another backup tool. Using /C without a post-copy manifest can leave a deceptively complete-looking folder. Using /Y from a scheduled batch file can overwrite the only known-good output. Each switch should be documented in the job record with the reason it is present.
Acceptance criteria
Before accepting an XCOPY job, confirm the exact source and destination, the resolved executable and version, the effective COPYCMD setting, the intended directory/attribute policy, and overwrite behavior. After copying, inspect the complete output and return code, verify the directory tree and any required metadata, and compare critical file bytes or trusted hashes. Keep the source untouched until the destination has been tested in its intended use.
Related:
- How to Archive FreeDOS Files Without Losing Names or Metadata
- FAT Timestamps on FreeDOS: Precision, Fields, and Timezone Limits
Sources: