LoginSignup
10
9

More than 5 years have passed since last update.

エクスプローラーで通常見れないフォルダ・ファイルの作り方(Windows/.NET/C#)システム隠しファイル

Last updated at Posted at 2015-07-01

エクスプローラーからは通常見れないフォルダ・ファイルを作る方法をご紹介します。

Windowsには、「隠しファイル」というものが存在しますが、
さらにその上をいく、「システム隠しファイル」を作ることができます。
ちなみに、これより上はWindows8.1現在、存在しません。

ディレクトリとファイルの属性に、

System.IO.FileAttributes.Hiddenと
System.IO.FileAttributes.System

を追加してやります。
以下、gistに貼ってあります。
https://gist.github.com/Koki-Shimizu/86b1dab64b6cf319658a

Program.cs
using System.IO;
namespace HiddenFolderMaker
{
    class Program
    {
        static void Main(string[] args)
        {
            var path = @"C:\temp\hidden2\";

            Directory.CreateDirectory(path);

            var directoryInfo = new DirectoryInfo(path);
            directoryInfo.Attributes |= System.IO.FileAttributes.Hidden;
            directoryInfo.Attributes |= System.IO.FileAttributes.System;

            var filepath = Path.Combine(path, "naisyo.txt");

            File.CreateText(filepath);

            var file_attr = File.GetAttributes(filepath);

            File.SetAttributes(filepath,file_attr | FileAttributes.Hidden);
            File.SetAttributes(filepath, file_attr | FileAttributes.System);
        }
    }
}

こうするとエクスプローラーのオプション設定にて、

 ファイルとフォルダーの表示にて、
「隠しファイル、隠しフォルダー、および隠しドライブを表示する」を選択します。
続いて、
「保護されたオペレーション システム ファイルを表示しない(推奨)」のチェックを外し、適用を行います。

Image.png

そうすると、やっと隠し状態で見れます。

Image.png

ちなみに、結局上記オプションを設定すれば見れちゃうじゃないか、と思われるかも知れませんが、イタチごっこになっちゃいますので、これ以上のレベルは追加しないようです。

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9