The Computer Oracle

Hiding files/folders which begin with a full stop (period)

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Beneath the City Looping

--

Chapters
00:00 Hiding Files/Folders Which Begin With A Full Stop (Period)
00:28 Accepted Answer Score 39
01:11 Answer 2 Score 12
01:38 Answer 3 Score 6
02:47 Answer 4 Score 3
03:30 Answer 5 Score 2
04:27 Thank you

--

Full question
https://superuser.com/questions/364406/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows7 #windowsexplorer

#avk47



ACCEPTED ANSWER

Score 39


ATTRIB +H /s /d C:\.* is the command to hide anything, directories included that start with a dot

This won't list the files (as stated below), but will hit every file it can access, and apply the Hidden attribute.

Once this is done, you can make sure that the Folder Options are set to hide hidden files. Click on Start, type folder options and press Enter. Click on the View tab, then choose Don't show hidden files, folders, or drives under Files and Folders \ Hidden files and folders. Hit Apply, then OK (or just OK).




ANSWER 2

Score 12


Simple:

In Windows Explorer

  1. Right click on the .folder you want to hide;
  2. Click properties, then click on the general tab;
  3. Click on hidden.

Done.

PS Only checked on Windows 7 Professional. PPS I noticed your question asked for doing this automatically. Clearly this won't cut it, but maybe readers find it useful.




ANSWER 3

Score 6


It is possible in C#, using System.IO.FileSystemWatcher. Code would be something like this. Just compile it and place it in the Start Up folder. But this code doesnt hide already existing files. So run first the code from Luke, and than this code. You need the System.IO and System.Security.Permissions

    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    public static void Run()
    {
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = "C:\\";
        watcher.IncludeSubdirectories = true;
        watcher.Filter = "*.*";
        watcher.Renamed += new RenamedEventHandler(OnRenamed);
        watcher.Created += new FileSystemEventHandler(watcher_Created);
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        watcher.EnableRaisingEvents = true;
        Console.WriteLine("Started...");
        while (true) ;
    }
    static void Check(string filename)
    {
        string name = Path.GetFileName(filename);
        if (name.StartsWith(".") && !File.GetAttributes(filename).HasFlag(FileAttributes.Hidden))
        {
            File.SetAttributes(filename, File.GetAttributes(filename) | FileAttributes.Hidden);
        }
    }
    static void watcher_Created(object sender, FileSystemEventArgs e)
    {
        Check(e.FullPath);
    }
    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        Check(e.FullPath);
    }
}



ANSWER 4

Score 3


Windows will hide files with the hidden or system flag. Or files may be hidden using ACL. Windows does not hide files based on filename.

To explicitly have Windows to hide files by filename, you'll need to explicitly create the feature. Either a file system driver (it use to be common for viruses to have this "feature") or a shell extension hack will work in this case.

On a side note, you can fake the feature by turning off "view file extensions" under Folder Options, since, to Explorer, a file that starts with a dot is a file with an extension, but no name.




ANSWER 5

Score 2


I wrote this powershell function which I placed in my powershell profile file so that whenever I start a new powershell session, the function is readily available.

function hide-dots {
    param([string]$path=".")

    if ($path -eq ".") {
        $cwd = (Get-Location).Path.Substring((Get-Location).Path.LastIndexOf("\") + 1)
        echo "Searching for files in $($cwd) ..."
    }
    else {
        echo "Searching for files in $($path) ..."
    }

    $Activity = "Hidding Dot Files."
    $isDotFile = {$_.name -match "^\..*"}
    $isNotHidden = {$_.attributes -match 'Hidden' -eq $false}
    $dotFileCount = 0
    $markedCount = 0

    Get-ChildItem $path -Recurse -Force -ErrorAction SilentlyContinue |
        where $isDotFile |
        where $isNotHidden |
        foreach {
            $path = $_.FullName
            $dotFileCount++

            Write-Progress `
                -Activity $Activity `
                -Status "Found $($dotFileCount) dot files."

            if ([System.IO.File]::Exists($path)) {
                Set-ItemProperty `
                    -name Attributes `
                    -value ([System.IO.FileAttributes]::Hidden) `
                    -path $path

                $markedCount++
            }   
        }


    echo "Marked $($markedCount) dot file(s) as hidden."
}

If not given a specified path it will recursively search for all dot files in the current directory and set the attribute of the file or folder as hidden.