Hiding Everything in a Folder without Hiding the Folder

1

I am trying to hide everything in a certain folder (with the exception of one file in the folder) without hiding the folder itself. This is what I have so far.

@ECHO OFF
cls
title Hide everything but useful shortcuts and program files
attrib +h "%CD:~0,3%Fix It Files" /S /D
attrib -h "%CD:~0,3%Fix It Files\Program Files" /S /D
attrib -h "%CD:~0,3%Fix It Files\%CD:~0,1% Shortcuts" /S /D
attrib -h "%CD:~0,3%Fix It Files"
exit

What we are looking at here is that I am trying to hide the folder called "Fix It Files" and everything in it in whatever drive the batch file is in. Then I unhide a two folders that I would rather stay unhidden; one I want to always be unhidden, the other depends on which drive it is in. Then I unhide the parent folder "Fix It Files".

At least, that is my goal. The issue is, while it hides and later unhides the folder "Fix It Files", all of the files inside stay unhidden.

A Child of God

Posted 2017-07-05T16:20:00.927

Reputation: 279

1Why don't you change your first attrib to attrib +h "%CD:~0,3%Fix It Files\*" /S /D andomit the last one? – LotPings – 2017-07-05T19:09:43.637

That works. Perhaps you make that into an answer so I can accept that – A Child of God – 2017-07-05T20:50:19.300

Answers

1

The crucial point seems to be first recursivly hiding your destination folder and as the last step unhiding it.

So better first hide everything inside the folder and below and only reveal the wanted items.

@ECHO OFF
cls
title Hide everything but useful shortcuts and program files
attrib +h "%CD:~0,3%Fix It Files\*" /S /D
attrib -h "%CD:~0,3%Fix It Files\Program Files" /S /D
attrib -h "%CD:~0,3%Fix It Files\%CD:~0,1% Shortcuts" /S /D
exit

LotPings

Posted 2017-07-05T16:20:00.927

Reputation: 6 150