Moving hidden files/folders with the command-line or batch-file
Question
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
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 thedir
anddel
commands do.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.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 tonul
).
(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.)
Solution 1:
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:
http://gnuwin32.sourceforge.net/downlinks/coreutils-bin-zip.php
Solution 2:
I just accomplished this using:
xcopy /H hidden_file destination_file
del /AH hidden_file
Solution 3:
Powershell v2:
move-item -force '--1.txt' newdirectory
also moves hidden files with hidden and system attributes set. Will work with files beginning with '--'.