Tools Links Login

Hide a folder or file the right way.

This code will hide any folder or file from windows explorer(By hide I mean even from those who have View hidden files and folders checked on View Screen Shot)

Original Author: SPY-3

Code

I was just informed about a built in vb function SetAttr %File or Folder%, vbSystem or vbHidden or vbNormal
My old code is below still.
I was messing around with some code and found how to hide folders and files(or atleast turn it into a system folder or file).
(if you were making a secure folder why not hide it the right way so you cant see it even if you have show hidden files and folders checked?)
The actual code is very very simple that anyone could do it (yet for some reason they dont) Heres the code:

To hide a folder simple use this code

Dim FS, F

Set FS = CreateObject("Scripting.FileSystemObject")

Set F = FS.GetFolder(%FOLDERPATH%) 'Replace %FOLDERPATH% with the folders path

F.Attributes = -1 ' -1 Makes it a system folder so its hidden from windows explorer(works for me on xp)

To unhide the folder simply put

Dim FS, F

Set FS = CreateObject("Scripting.FileSystemObject")

Set F = FS.GetFolder(%FOLDERPATH%) 'Replace %FOLDERPATH% with the folders path

F.Attributes = 0 ' This returns the folder to normal in windows explorer

To hide files simply use this code

Dim FS, F

Set FS = CreateObject("Scripting.FileSystemObject")

Set F = FS.GetFile(%FILEPATH%) 'Replace %FILEPATH% with the files path

F.Attributes = -1 ' -1 Makes it a system file so its hidden from windows explorer(works for me on xp)


To unhide the file simply put

Dim FS, F

Set FS = CreateObject("Scripting.FileSystemObject")

Set F = FS.GetFile(%FILEPATH%) 'Replace %FILEPATH% with the files path

F.Attributes = 0 ' This returns the file to normal in windows explorer




Hope this code helps and please leave feedback and/or vote.

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 300 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.