0

I had a virus or something on my computer that set the attributes for all the folders in the root of my external drive to system and hidden, and created shortcuts to them. I am now trying to remove these attributes all at once with the following command, but it doesn't do anything:

dir /ash /b | attrib -h -s

According to my understanding of the documentation of these commands, this should work. Is there something wrong here?

Thanks

2 Answers 2

1

Yes. The pipe | redirects program 1’s output to program 2’s input. However, your program 2 (attrib), does not read any input. It wasn’t written to do so. Instead, it expects file names in its command-line parameters.


There are some tools available in Unix-style systems to handle piping of arguments—though of little relevance here—they are:

  • xargs to handle such cases of converting text input into command-line arguments
  • find to handle this specific case of applying a command recursively
  • chmod command that has a “recursive mode” option

On Windows, without xargs, you will have to do something like:

for /f "tokens=*" %f in ('dir/b/ash') do @attrib -r -h -s "%~f"

Or maybe:

for /r . %f in (*) do @attrib -r -h -s "%~f"
2
  • What a roundabout way of doing things! attrib supports recursion natively, see keltari's answer.
    – Karan
    Commented Feb 5, 2013 at 2:01
  • Thanks for the explanation as to why it doesn't work. I will try your suggestions. On the other hand, I could also just use my linux machine to do this, although I am not exactly sure how the windows attributes will translate into a linux environment, For instance, this particular thing is not a problem when I just connect the drive to my linux machine (because of the .filename used for hidden folders in unix)
    – user195487
    Commented Feb 5, 2013 at 5:39
1

Actually you can do it in a much easier fashion:

attrib e:\*.* -s -h /s

This will remove all the system and hidden attributes starting at the root of the E: drive and all its sub-directories. The /s tells attrib to process sub-directories.

2
  • Can also add /d if the directories have been affected as well.
    – Karan
    Commented Feb 5, 2013 at 2:01
  • I also considered this option, but only the directories were affected, and only in the root of the drive. I suppose it could not do any harm do do it this way, other than changing the attributes for files that needs to stay hidden and system. I could also use the attrib command on the folders individually, but of course that will take a long time. I was just frustrated that it didn't work although I figured it should.
    – user195487
    Commented Feb 5, 2013 at 5:35

You must log in to answer this question.