-
Jan 17th, 2014, 10:34 PM
#1
Thread Starter
New Member
Unhide all files and folders
Hi,
I'm new for programming and visual basic.
Can anyone help me code for
1. Change all folders, subfolders and files to attribute NORMAL in a drive (e.g E:\), if it not set as attribute NORMAL?
2. The code also has to show number of total folders and total files has been changed to attribute NORMAL.
3. The code also has to skip to next if access denied.
Note:-The drive letter pass from a ComboBox. I already created vb code for this.
Thanks.
-
Jan 18th, 2014, 05:26 AM
#2
Hyperactive Member
Re: Unhide all files and folders
You can unhide all files and folders in Windows options. Let me know what version of Windows you are running and I can give instructions. Is there some reason that you need to do it programatically? I mean programs do not need files to be unhidden in order to access them, so the only reason to unhide them is so the user can see them. So just doing it in Windows options seems the best way.
-
Jan 18th, 2014, 01:18 PM
#3
Re: Unhide all files and folders
The basic command you need is ...
IO.File.SetAttributes(filepath, IO.FileAttributes.Normal)
To decide on an action when an exception is thrown such as denied access use a Try/Catch clause. There's plenty of documentation available for that. The rest of it looks like pretty straightforward stuff so take a stab at it and let us know if there are any problems.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 18th, 2014, 01:27 PM
#4
Re: Unhide all files and folders
<2 cents>
I'm sure there is a need for this, but it seems like a bad idea to show hidden folders files from an application. Files and folders are typically hidden for a reason; to keep the innocents from mucking around in system files and other things they should not be mucking in. If a user need to see hidden files, then they are probably saavy enough to show them through the explorer. However for a user that doesn't even know there is such a thing as hidden files, very little good can be had by showing them.
</2 cents>
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Jan 20th, 2014, 08:45 AM
#5
Thread Starter
New Member
Re: Unhide all files and folders
Originally Posted by Maverickz
You can unhide all files and folders in Windows options. Let me know what version of Windows you are running and I can give instructions. Is there some reason that you need to do it programatically? I mean programs do not need files to be unhidden in order to access them, so the only reason to unhide them is so the user can see them. So just doing it in Windows options seems the best way.
As I know we can unhide file using CMD.
I'm creating an application to unhide hidden files and folders in a selected
Code below works fine for just 1 file. but I need a code for unhilde all hidden filles and folders.
Dim path As String = "H:\Test.txt"
' Create the file if it exists.
Dim attributes As FileAttributes
attributes = File.GetAttributes(path)
If (attributes And FileAttributes.Hidden) = FileAttributes.Hidden Then
' Show the file.
File.SetAttributes(path, FileAttributes.Normal)
Console.WriteLine("The {0} file is no longer hidden.", path)
End If
-
Jan 20th, 2014, 08:49 AM
#6
Thread Starter
New Member
Re: Unhide all files and folders
Originally Posted by dunfiddlin
The basic command you need is ...
IO.File.SetAttributes(filepath, IO.FileAttributes.Normal)
To decide on an action when an exception is thrown such as denied access use a Try/Catch clause. There's plenty of documentation available for that. The rest of it looks like pretty straightforward stuff so take a stab at it and let us know if there are any problems.
I managed to create a code for unhide one selected hidden file.
but don't know how to unhide all files and folders in a drive.
-
Jan 20th, 2014, 08:53 AM
#7
Thread Starter
New Member
Re: Unhide all files and folders
Originally Posted by kebo
<2 cents>
I'm sure there is a need for this, but it seems like a bad idea to show hidden folders files from an application. Files and folders are typically hidden for a reason; to keep the innocents from mucking around in system files and other things they should not be mucking in. If a user need to see hidden files, then they are probably saavy enough to show them through the explorer. However for a user that doesn't even know there is such a thing as hidden files, very little good can be had by showing them.
</2 cents>
Before pass the drive letter to unhide code, a combobox will filter to unselect any Windows patitition and CD-ROM. So This won't be a problem.
-
Jan 20th, 2014, 09:09 AM
#8
Re: Unhide all files and folders
Use a simple loop on the results from My.Computer.Filesystem.GetFiles or IO.Directory.GetFiles
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 20th, 2014, 10:28 AM
#9
Thread Starter
New Member
Re: Unhide all files and folders
Originally Posted by dunfiddlin
Use a simple loop on the results from My.Computer.Filesystem.GetFiles or IO.Directory.GetFiles
Can you please tell me why my code below not working?
Imports System
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Drive As String = "H:\"
Dim DriveObj As DirectoryInfo
DriveObj = New DirectoryInfo(Drive)
Dim Files As FileInfo() = DriveObj.GetFiles("*.*")
Dim Drives As DirectoryInfo() = DriveObj.GetDirectories("*.*")
Dim Filename As FileInfo
For Each Filename In Files
On Error Resume Next
If (Filename.Attributes And FileAttributes.Hidden) = FileAttributes.Hidden Then
' Show the file.
File.SetAttributes(Filename.Attributes, FileAttributes.Normal)
End If
Next
Dim DirectoryName As DirectoryInfo
For Each DirectoryName In Drives
On Error Resume Next
If (DirectoryName.Attributes And FileAttributes.Hidden) = FileAttributes.Hidden Then
' Show the file.
File.SetAttributes(DirectoryName.Attributes, FileAttributes.Normal)
End If
Next
End Sub
End Class
-
Jan 20th, 2014, 10:46 AM
#10
Re: Unhide all files and folders
Well what does 'not working' mean? I can say that I'm extremely unwilling to let you leave On Error Resume Next in there. It would be kind of useful to know if there are errors rather than ignoring them! Also File.SetAttributes(Filename.Attributes, FileAttributes.Normal) is clearly wrong as the first parameter should be the filepath (as String and in full) which Filename.Attributes obviously isn't.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 20th, 2014, 10:05 PM
#11
Thread Starter
New Member
Re: Unhide all files and folders
Originally Posted by dunfiddlin
Well what does 'not working' mean? I can say that I'm extremely unwilling to let you leave On Error Resume Next in there. It would be kind of useful to know if there are errors rather than ignoring them! Also File.SetAttributes(Filename.Attributes, FileAttributes.Normal) is clearly wrong as the first parameter should be the filepath (as String and in full) which Filename.Attributes obviously isn't.
My code below able to unhide specified hidden folder and or file. Now my problem is, I don't know how to create a loop to unhide all hidden files, folders and subfolders in specified Drive. Can you please help me to create a loop in my code below to unhide (Make it NORMAL) all files, folders and subfolders if it was hidden. Just assume variable for specified Drive is MyDrive.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MyDrive As String = "H:\"
Dim MyFile As String = MyDrive + "test.txt"
Dim MyFolder As String = MyDrive + "Test"
If (IO.File.GetAttributes(MyFile) And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then
' Show the file.
IO.File.SetAttributes(MyFile, IO.FileAttributes.Normal)
End If
If (IO.File.GetAttributes(MyFolder) And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then
' Show the folder.
IO.File.SetAttributes(MyFolder, IO.FileAttributes.Normal)
End If
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|