Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with reserved DOS names #56

Open
wischi-chr opened this issue Dec 21, 2016 · 0 comments
Open

Problems with reserved DOS names #56

wischi-chr opened this issue Dec 21, 2016 · 0 comments

Comments

@wischi-chr
Copy link

CON, AUX, LPT, etc. were reserved names in MsDos. For compatibility Windows Explorer still prevents you from creating files or directories with those names. But in fact Windows internally does support it (like it supports long filenames even tho the Explorer does not).

Would be great if those names would be handled correctly.
The following example demonstrates that. Pri.LongPath is not able to create a directory named "aux".

using System;
using System.Runtime.InteropServices;
using Pri.LongPath;

namespace MetaTree
{
    class Program
    {
        //Make sure temp already exists!
        private readonly static string temp = @"D:\Temp\";

        static void Main(string[] args)
        {
            //[System.ArgumentException]: The UNC path should be of the form \\server\share.
            Directory.CreateDirectory(temp + "aux");

            //With the WinAPI a prefix is needed, but it works
            CreateDirectory(@"\\?\" + temp + "aux", IntPtr.Zero);

            //Removes the aux Folder
            //WARNING: The "aux" folder can not be removed with the windows explorer
            RemoveDirectory(@"\\?\" + temp + "aux");
        }

        [DllImport("kernel32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes);

        [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        static extern bool RemoveDirectory(string lpPathName);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants