Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98690 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79986 invoked from network); 30 Mar 2017 18:06:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2017 18:06:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.162 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.162 mx206.easyname.com Received: from [212.232.25.162] ([212.232.25.162:42715] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/00-13909-3394DD85 for ; Thu, 30 Mar 2017 13:06:43 -0500 Received: from cable-81-173-134-58.netcologne.de ([81.173.134.58] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cteRW-0005US-7m; Thu, 30 Mar 2017 18:05:09 +0000 Reply-To: internals@lists.php.net References: To: Rasmus Schultz , PHP internals Message-ID: <4daabd46-4dc2-1c33-f89f-664f803c6cd5@fleshgrinder.com> Date: Thu, 30 Mar 2017 20:05:03 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] Directory separators on Windows From: php@fleshgrinder.com (Fleshgrinder) On 3/30/2017 3:25 PM, Rasmus Schultz wrote: > Thoughts? > Windows and paths is a complicated and lengthy story. TL;DR all versions of Windows are able to deal with slashes, and we could easily use slashes everywhere all the time. # History The story why Windows is using the backslash might be of interest, read: http://blogs.msdn.com/b/larryosterman/archive/2005/06/24/432386.aspx This also explains that Windows IS supporting forward slashes since at least the 1990s. However, there are programs that have significant problems with it, but usually those are old or otherwise shitty programs. There are various ways paths can be represented in Windows, the so called path variants. There are 7 in total: 1. Root 2. Disk 3. UNC 4. Device Namespace 5. Verbatim Disk 6. Verbatim UNC 7. Verbatim Device Namespace ## Root This works just line on Unix an can be either `\` or `/`. It always refers to the root directory of the current drive. ### Home PowerShell also supports the home short-hand `~` like Unix systems, however, `cmd.exe` does not. ## Disk This is the one we all know. The drive letter comes first, followed by a colon `:`, and then continues with the actual path. `C:\Folder\Resource` `C:/Folder/Resource` ## UNC Is short for **Universal Naming Convention** or **Uniform Naming Convention** allows one to refer to network paths or server shares. `\\ComputerName\SharedFolder\Resource` `//ComputerName/SharedFolder/Resource` It also has an extended form for web resource: `\\CompuserName[@SSL][@Port]\SharedFolder\Resource` ## Device Namespace This allows one to directly address special devices, or again the disks themselves. `\\.\Device\Resource` `//./Device/Resource` ## Verbatim * The verbatim paths work exactly the same way as the respective normal counterpart, the difference is that the slash to backslash conversion does NOT happen auto-magically: `\\?\C:\Folder\Resource` `\\?\Server\Share` `\\?\UNC\Server\Share` https://en.wikipedia.org/wiki/Path_(computing) I highly recommend you to have a look at Rust's path implementation, as it takes care of all these things in a very intelligent manner. It is also capable of dealing with all variants of paths in Windows, unlike PHP which only supports a few: https://doc.rust-lang.org/std/path/index.html -- Richard "Fleshgrinder" Fussenegger