# Solved: Checking if file or folder is hidden attrib - command line batch question



## scrfix (May 3, 2009)

Is there a way to check if the file or folder is marked as hidden?

I understand that I can utilize the attrib function

Here is an example:

G:\testing has is marked as hidden.
The testing directory within G also has a file in it called testing.txt and it is marked as hidden.

I would like, from the command line, in a batch file, to be able to look at the folder testing and check to see if it is marked as hidden. If it is hidden, I would like to uncheck the hidden attribute (ie -h) for itself and all files and folders contained within it.

I have attempted multiple different methods however I keep getting that /H or H was unexpected at this time.

I know that I can just tell it to do that automatically however I was hoping to utilize an IF statement in there with this command. Just cannot figure out how to get the command to work within an IF statement.

Any ideas?

A quick search for attrib /? shows me the following:

G:\>attrib /?
Displays or changes file attributes.
ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I]
[drive:][path][filename] [/S [/D] [/L]]
+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
I Not content indexed file attribute.
[drive:][path][filename]
Specifies a file or files for attrib to process.
/S Processes matching files in the current folder
and all subfolders.
/D Processes folders as well.
/L Work on the attributes of the Symbolic Link versus
the target of the Symbolic Link

Thanks,


----------



## TheOutcaste (Aug 8, 2007)

```
For /F "Delims=" %%I In ('Attrib C:\test1') Do Set _Attribs=%%I
If "%_Attribs:~4,1%"=="H" (
Attrib -H C:\test1
Attrib /D /S -H C:\Test1\*.*
)
```
Don't really need an If statement:

```
For /F "Delims=" %%I In ('Attrib C:\test1^|Findstr /BR "....H"') Do (
Attrib -H C:\test1
Attrib /D /S -H C:\Test1\*.*
)
```


----------



## scrfix (May 3, 2009)

What does the .... do? I understand that it is a wild character and allows anything. My question is what purpose does that serve?


----------



## TheOutcaste (Aug 8, 2007)

Since you are checking to see only if the item is hidden, we don't care what the first 4 attributes are. We can't just search for an H though, as the item name may contain an H.
So we specify the search string must match at the beginning of the line (*/B*), and the 4 wild cards (*.*) will match the first 4 attributes whether they are set or not. Means "look for lines with the 5th character equal to H"

There's 8 basic attributes in XP but Attrib only shows 4 of them, displaying a space for the rest:
Pos. Attribute
*A*rchive
*D*irectory
*V*olume
*S*ystem
*H*idden
*R*eadOnly
*C*ompressed
*L*ink (aka Alias or ReparsePoint)
Not 100% sure about the order of the last two but the spacing would indicate they left room for them. VBScript can list all 8.
Vista adds *Not Content Indexed*, shown as *I* in the Prompt, *N* in Windows Explorer. The file name was moved _two_ spaces to the right though, but seems they only added the one attribute. Would be handy if they had added the Temp attribute, that could be very useful, as well as Encrypted and Compressed.
They are displayed in this order:

```
1234567890
A[COLOR=SlateGray]DV[/COLOR]SHR[COLOR=SlateGray]CL[/COLOR]I[COLOR=DarkRed]?[/COLOR]
```


----------



## scrfix (May 3, 2009)

Nevermind, I think I just found the issue.


----------



## TheOutcaste (Aug 8, 2007)

I'm guessing you needed to put quotes around *%drivecombo%%folder%* because of the space in the folder name.
I'm always forgetting the quotes; don't go picking up my bad habits now...


----------



## scrfix (May 3, 2009)

lol... That is what I figured out. Man you are quick. That post wasn't up there longer than a couple of seconds before I edited it to say I figured it out.


----------



## TheOutcaste (Aug 8, 2007)

I'm just psychic. Or is that psychotic?

Actually, the original goes out in the email notification, no matter how fast you edit.


----------



## scrfix (May 3, 2009)

I forgot about that. I barely utilize that email function. It comes in hotmail and is all messed up so I always click on the link to get here.


----------

