15
4
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.)
4If you are creating the
\temp
directory, why not just rename/move the%1
directory to\temp
? Or is that just the simplified case? – Ken – 2012-02-22T23:27:49.830That is indeed a simplified case. Simply renaming would not work. – Synetech – 2012-02-23T01:15:28.900
Why is stripping an attribute not an option? That would be the proper (and intended) way to do it. – Rook – 2012-02-23T01:39:28.580
> Why is stripping an attribute not an option? @Idigas, how exactly would you know which attributes were set on each and every item so that they can correctly be re-set? > That would be the proper (and intended) way to do it That doesn’t sound right, at all. – Synetech – 2012-02-23T01:47:19.377
Forgive my ignorance, but would something like http://www.jamesewelch.com/2008/05/01/how-to-write-a-dos-batch-file-to-loop-through-files/ work?
– Dr Kitty – 2012-02-25T22:07:15.660@TheElectricMuffin, probably not. I already use
for /d
to move all of the directories in the source to the target. However, usingfor
*may* work for files too. I’ll run some tests in a second to confirm, but I suspect that thefor
andmove
commands can both see through hidden and system attributes. If that’s the case, then you will have done it! I’ll be right back… – Synetech – 2012-02-25T22:12:11.220@TheElectricMuffin bad news. It didn’t work. Neither
for
, normove
can see hidden files. Worse, neither has any attribute options likedel
ordir
.:-(
– Synetech – 2012-02-25T22:13:54.870In fact, even using
for /f "delim=s" %i in ('dir /a /b "..."') do move %i ...
won’t work. The simplest case just won’t; for example, ifc:\foobar.txt
is hidden (or system…), thenmove c:\foobar.txt c:\blah
won’t work becausemove
cannot understand hidden files, even when they are explicitly named. – Synetech – 2012-05-20T01:37:01.573Regarding what you say of robocopy. I wonder if MOVE also copies then deletes source. it is safer to do that. I suppose the way to test would be to repeatedly do DIR on both. The unix mv command apparently does copy and remove. If things are so slow, I suggest getting an SSD drive if you haven't already. i think it made a slow atom boot windows 7 faster than an intel core i5! moving/cut and pasting files, is v quick within the same file system because it just removes and creates a new link(according to mv) and i've heard similar things for windows hence can be so fast. – barlop – 2012-12-15T11:45:37.303
@barlop, an SSD isn’t really a fix because links require using NTFS instead of FAT32, and moreover, it doesn’t really improve things all that much when it comes to moving a couple of thousand tiny files instead of a few large ones. – Synetech – 2012-12-15T21:23:45.170