Windows – Moving hidden files/folders with the command-line or batch-file

batch filecommand linefile-transferwindows


Does anyone know of a way to move files and folders that have the hidden, system, or read-only attribute set from the command-line or a batch file? (No, stripping the attributes first is not an option since there is no practical way to know which attributes were set in order to re-set them after the move.)

(Failed) Attempts

  1. Using the basic move command does not work with items with the hidden or system attribute set and for some reason, it does not have switches to specify attributes like the dir and del commands do.

  2. I tried using a utility I wrote that uses the shell’s file operation function, but that requires using start /w to prevent the batch file from running on ahead, and it complains about long-filename support for some reason.

  3. I tried using robocopy, but it first copies the files and then deletes the originals instead of simply moving the source (which results in a frustrating delay, even with the excessive output redirected to nul).

(Surprisingly it seems that few people have ever needed to move hidden files from the command-line. All I could find was this one person who abandoned the attempt.)

Best Answer

I've been able to successfully move read-only, hidden files using MV.EXE from the GNU for Win32 utilities. The target file retains the read-only, hidden attributes.

You'll have to download the entire package: