Click here to Skip to main content
12,394,971 members (68,958 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

8.2K views
777 downloads
10 bookmarked
Posted

Find Hidden Files from Computer

, 8 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This article describes how to show file name extensions, hidden folders/files, and system folders/files in your system.

Sample Image

Introduction

You may have certain file name extensions hidden within Windows. We will see how to see the full file/folder names, extensions in the following section. I tried to make a simple app to find hidden files with a few clicks using C# code. If you know the name of a hidden file or folder, you can search for it.

Class for File information

First create a class to keep file information. Class details are shown below where it keeps extension, full name, file size, and if it is hidden etc.

public class PcFile
{
    public string Extension { get; set; }
    public string FullName { get; set; }
    public string FileSize { get; set; }
    public long FileLength { get; set; }
    public DateTime CreationTime { get; set; }
    public string FileName { get; set; }
    public string Date { get; set; }
    public bool isReadOnly { get; set; }
    public bool isHidden { get; set; }
    public bool isArchive { get; set; }
    public bool isSystem { get; set; }
}

Using the design

In the design I have taken FolderBrowserDialog to choose a directory or drive, DataGridView to show the list of file details, radiobutton list all or hidden file option, treeview to get a folder hierarchy, and listbox to get extension wise files so the design of the page is as shown above.

Using the code

Code starts with a simple way where I browse the folder path and keeping txtPath.Text = folderBrowserDialog1.SelectedPath; then getting the folder hierarchy in a treeview with the following method:

void ListDirectory()
{
    treeView1.Nodes.Clear();
    var rootDirectoryInfo = new DirectoryInfo(txtPath.Text);
    treeView1.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
    LoadFileDetails("");
}
TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
{
    var directoryNode = new TreeNode(directoryInfo.Name);
    try
    {
        foreach (var directory in directoryInfo.GetDirectories())
        {
            directoryNode.Nodes.Add(CreateDirectoryNode(directory));
            GetallFileInformation(directory.FullName);
        } 
    }
    catch (UnauthorizedAccessException) { }
    catch (Exception) { }
    return directoryNode;
}

In the above method we are collecting the folder hierarchy and calling the GetAllFileInformation method to store file information of current directories. See the following method where it is coded to keep file information.

static List<PcFile> listParent = new List<PcFile>();
void GetallFileInformation(string path)
{
    try
    { 
        string[] files = Directory.GetFiles(path, "*.*", System.IO.SearchOption.TopDirectoryOnly);
        foreach (string file in files)
        {
            FileInfo info = new FileInfo(file);
            PcFile pc = new PcFile();
            pc.Extension = info.Extension;
            pc.FullName = info.FullName;
            pc.FileLength = info.Length;
            pc.CreationTime = info.CreationTime;
            pc.FileName = info.Name;
            pc.FileSize = String.Format(new FileSizeFormatProvider(), "{0:fs}", pc.FileLength);
            pc.isArchive = Common.isArchive(pc.FullName);
            pc.isHidden = Common.isHidden(pc.FullName);
            pc.isReadOnly = Common.isReadOnly(pc.FullName);
            pc.isSystem = Common.isSystem(pc.FullName);
            if (listParent.Exists(x => x.FullName == info.FullName) == false)
                listParent.Add(pc);
        }
    }
    catch { }
}

See in this method all file information are added to a static list of pcFile class. In this case we are loading all the file information the first time to a static list; after any indexing we just filter from this list. In case of hidden files, get files by extension or by folder and so on.

lstExtentions.DataSource = (from f in listParent.AsParallel()
                                      select new { Extention = f.Extension.ToLower() }).
                                      OrderBy(x => x.Extention).Distinct().ToList();
var linqFileDetails = (from f in listParent.AsParallel()
                       select new
                       {
                           FileName = f.FileName,
                           FullName = f.FullName,
                           FileSize = f.FileSize,
                           CreationTime = f.CreationTime,
                           Extension = f.Extension
                       }).Distinct().ToList();
dgFileDetails.DataSource = linqFileDetails;

In another method filter its extensions and load into listbox where it will help us check by extension and another for the DataGridView to load some specific information. You will get its detail in the demo app or after downloading the code.

File View

In the above picture you can mark hidden radio button is selected where extensions are showing those types of hidden files are exists in your selected folder. After that grid is loaded with gif extensions file on listbox item selection. See in this case if you are choosing any item from DataGridView if you are clicking on File Name it will open the selected file in your desktop. This is one easy solution to find hidden file and open that file.

History

In this article I have just tried to find the hidden type of files from your system. Download the demo project to check independently in your system. But for that you have to check if ASP.NET Framework 4.0 exists or not. If not download latest framework from the Microsoft website and install it into your system.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Comments and Discussions

 
QuestionWhy your own class to store the file information? Pin
John Brett8-Nov-13 5:59
memberJohn Brett8-Nov-13 5:59 
AnswerRe: Why your own class to store the file information? Pin
sankarsan parida8-Nov-13 6:22
professionalsankarsan parida8-Nov-13 6:22 
GeneralMy vote of 5 Pin
fredatcodeproject8-Nov-13 5:39
memberfredatcodeproject8-Nov-13 5:39 
GeneralRe: My vote of 5 Pin
sankarsan parida8-Nov-13 5:43
professionalsankarsan parida8-Nov-13 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 8 Nov 2013
Article Copyright 2013 by sankarsan parida
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid