0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Windowsにおけるディレクトリ、フォルダ、パスの使い分けー絶対パスと相対パスとセグメントまでの整理1/2

Last updated at Posted at 2020-09-01

#Directoryが正統派
所詮フォルダはGUIで描くときにフォルダの絵で書いたからフォルダーである。
というのもUNIXとWindowsのGUIを使っていない版というか、先代のMidrosoft Disk Operating System MS-DOSはどっちが早かったかというと
Wikipedia基準で行くと
UNIX 1971
MS-DOS 1981
と10年の開きがある。
つまりディレクトリが正統派である。
http://masudahp.web.fc2.com/vb6/vb6first/fileinout01.html

 フォルダとディレクトリは同じものを表している。当初、UNIXやMS-DOSなどのOSではディレクトリと呼ばれていたが、Windowsではフォルダと呼ばれるようになった。VBにもDirListBoxコントロール(フォルダを選択するリストボックス)があり、このDirはDirectory(ディレクトリ)の略である。

MirosoftにありがちなやらなくてもいいことをやってユーザーはおろかMicrosoftまで混乱するという典型例である。

ただしディレクトリではないフォルダもある。
「ディレクトリ」と「フォルダ」の違いと共通点

  • コントロールパネルはフォルダであってディレクトリではない。
  • また、圧縮ファイルや、メタデータの一部などもフォルダとみなされるのがディレクトリとの違いです。
たしかにコントロールパネルという概念はMS-DOSにはなかった。 Windowsはフォルダとコントロールパネルを使い始めたので、コントロールパネルがフォルダなのは頷ける。 ただし圧縮ファイルがフォルダとして扱われるのはWindowsの都合だと思われる。 もともとzip形式やlha形式といった圧縮形式はDOSの時代から存在しているからだ。 またプライベートフォルダや隠しフォルダもDOSの時代にはない。存在していたのは隠しファイルである。

ディレクトリとパス

Windows 系 OS および MS-DOS
Windows 系 OS のディレクトリ記述方法は、Microsoft社が Windows 以前から発売していた MS-DOS のディレクトリ表記を引き継いでいます。UNIX / Linux でのディレクトリ区切り文字 / (スラッシュ) の代わりに \ (バックスラッシュ) が用いられます。ルートディレクトリは \ となり、相対パスで親ディレクトリを表すのは .. で UNIX / Linux と同じです(Windows上ではディレクトリとは言わずフォルダと言います)。但し、このルートディレクトリの前には、補助記憶装置(ハードディスク等)のパーティションやDVD装置、USBメモリ等を「ドライブ」と称してアルファベットで区別し、その個々にディレクトリツリーが構成されます。ドライブの区別はアルファベット1文字に : (コロン) を付けたものをドライブ記号として用い、その後ろにディレクトリのパスを記述します。結果的に、絶対パス表記はドライブ名も含めた形で記述することになります。

DirectoryをGUIにしたときがフォルダ

FilesystemObjectなどはFolderオブジェクトしているが、本来はDirectory Objectにすべきであった。
一部の例外は本当に例外すぎるのでディレクトリとフォルダは同じだと思って良い。
上記の違いがあるが、上記のような例外を意識することはほぼないと思われる。

パスとは?

例えば環境変数を設定するとき、環境変数はPATHとなり、PATH=以下定義していく。ディレクトリでもフォルダではない。
Docs .NET .NET API ブラウザー System.IO Path

パスは、ファイルまたはディレクトリの場所を提供する文字列です。
パスがディスク上の場所を指しているとは限りません。たとえば、パスは、メモリ内またはデバイス上の場所にマップされる場合があります。 パスの正確な形式は、現在のプラットフォームによって決まります。
たとえば、一部のシステムでは、パスはドライブまたはボリューム文字で開始できますが、この要素は他のシステムには存在しません。 一部のシステムでは、ファイルパスに拡張子を含めることができます。拡張子は、ファイルに格納されている情報の種類を示します。 ファイル名拡張子の形式はプラットフォームに依存します。たとえば、一部のシステムでは拡張機能を3文字に制限していますが、そうでない場合もあります。 また、現在のプラットフォームでは、パスの要素を区切るために使用する文字セットと、パスを指定するときに使用できない文字のセットも決定されます。 これらの違いにより、クラスのフィールド Path と、クラスの一部のメンバーの正確な動作 Path は、プラットフォームに依存します。

パスには、絶対または相対位置情報を含めることができます。 絶対パスは、場所を完全に指定します。ファイルまたはディレクトリは、現在の場所に関係なく一意に識別できます。 相対パスは、部分的な場所を指定します。相対パスで指定されたファイルを検索するときに、現在の場所が開始点として使用されます。
現在のディレクトリを確認するには、 Directory.GetCurrentDirectory を呼び出します。
A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path might map to a location in memory or on a device. The exact format of a path is determined by the current platform. For example, on some systems, a path can start with a drive or volume letter, while this element is not present in other systems. On some systems, file paths can contain extensions, which indicate the type of information stored in the file. The format of a file name extension is platform-dependent; for example, some systems limit extensions to three characters, and others do not. The current platform also determines the set of characters used to separate the elements of a path, and the set of characters that cannot be used when specifying paths. Because of these differences, the fields of the Path class as well as the exact behavior of some members of the Path class are platform-dependent.

A path can contain absolute or relative location information. Absolute paths fully specify a location: the file or directory can be uniquely identified regardless of the current location. Relative paths specify a partial location: the current location is used as the starting point when locating a file specified with a relative path. To determine the current directory, call Directory.GetCurrentDirectory.

.NET Core 1.1 and later versions and .NET Framework 4.6.2 and later versions also support access to file system objects that are device names, such as "?\C:".

For more information on file path formats on Windows, see File path formats on Windows systems.

Most members of the Path class do not interact with the file system and do not verify the existence of the file specified by a path string. Path class members that modify a path string, such as ChangeExtension, have no effect on names of files in the file system. Path members do, however, validate the contents of a specified path string, and throw an ArgumentException exception if the string contains characters that are not valid in path strings, as defined in the characters returned from the GetInvalidPathChars method. For example, on Windows-based desktop platforms, invalid path characters might include quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0), and Unicode characters 16 through 18 and 20 through 25.

The members of the Path class enable you to quickly and easily perform common operations such as determining whether a file name extension is part of a path, and combining two strings into one path name.

All members of the Path class are static and can therefore be called without having an instance of a path.

Note

In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception in most cases. Ensure that your paths are well-formed when using methods that accept a path string.

つまりPathとはファイルやディレクトリ(フォルダ)の経路と位置を表す文字列

原文はLocationとなっているが、WindowsにおけるPathとは経路と位置と訳さざるを得ない。
あるプラットフォームにおいてディレクトリやファイルの経路と位置を示すものがPathとなる。
またこのDotNetやC#の解説はFolderとしているものは殆どない。
ここでもDirectoryという表現が正統なのがわかる。
ここで経路と位置といわないと、次の絶対パスと相対パスがわかりづらくなる。まあ絶対位置と、相対位置でも良いのかもしれないが。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?