VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Hide a folder or file the right way.

by SPY-3 (5 Submissions)
Category: Coding Standards
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (8 Votes)

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)

Rate Hide a folder or file the right way.

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.

Download this snippet    Add to My Saved Code

Hide a folder or file the right way. Comments

No comments have been posted about Hide a folder or file the right way.. Why not be the first to post a comment about Hide a folder or file the right way..

Post your comment

Subject:
Message:
0/1000 characters