Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

  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.)

share|improve this question
3  
If you are creating the \temp directory, why not just rename/move the %1 directory to \temp? Or is that just the simplified case? – Ken Feb 22 '12 at 23:27
That is indeed a simplified case. Simply renaming would not work. – Synetech Feb 23 '12 at 1:15
Why is stripping an attribute not an option? That would be the proper (and intended) way to do it. – ldigas Feb 23 '12 at 1:39
> 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 Feb 23 '12 at 1:47
Forgive my ignorance, but would something like jamesewelch.com/2008/05/01/… work? – Dr Kitty Feb 25 '12 at 22:07
show 5 more comments

2 Answers

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

share|improve this answer
Not bad. That works, unfortunately it dies when dealing with files that start with --; it thinks that it is an argument instead of a filename. – Synetech Mar 23 '12 at 1:00
Not bad? Thats it? It solves your request. I don't see anything about the '--filename' requirement, or I would have tested for it. Apologies, but hidden requirements are poor sport. – RobW Mar 23 '12 at 16:00
Yes, not bad. It does only the basic operation I asked about. If it cannot handle valid Windows filenames, then it is not very useful now is it? Handling filenames correctly is not a “hidden” requirement. – Synetech Mar 23 '12 at 17:13
Well, that's an ethical stretch. "...move files and folders that have the hidden, system, or read-only attribute set...". Nothing basic about this question. You said "...surprisingly few...". If you're asking for time in exchange for 'solved' points, for a problem you know is not straightforward, holding back on requirements isn't very fair. I too don't mind rejecting a solution which does not fit the description, but at least I'll try to include the obscure gotcha's in advance. – RobW Mar 23 '12 at 23:08
What’s obscure about the tool being able to handle valid filenames? It’s not my fault the port has a bug. – Synetech Mar 24 '12 at 3:21
show 2 more comments

Powershell v2:

move-item -force   '--1.txt' newdirectory

also moves hidden files with hidden and system attributes set. Will work with files beginning with '--'.

share|improve this answer
I’m sure that would work, but PowerShell is excruciatingly slow compared to the normal command-prompt. And no, that is not a “hidden” requirement, I clearly indicated my dislike of the delay of Robocopy in the question. (Please don’t tell me that it works fast on your system because that does not help me in any way. On my system it takes several seconds simply to load, and even just pressing Tab to complete a filename takes >1 second which is order of magnitude slower than in cmd. So unless you’re willing to buy me a new system, then PS is not going to help.) – Synetech Mar 24 '12 at 3:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.