Search code examples
c#.net-4.5ntfscreate-directory

How to create folder with trailing dot (.) in .NET/C#?


I need to create folders with trailing dots (.) using C#. Here is my code:

System.IO.Directory.CreateDirectory("d:\\MyCorp Inc.");

But the folder is created without the final dot. Is there a solution?

I am using .NET Framework 4.5/C#. My file system is NTFS, on Windows 8.


Solution

  • Try:

    using System.Runtime.InteropServices;
    class Program
    {
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes);
    
        private static void Main(string[] args)
        {
            CreateDirectory(@"\\?\c:\temp\MyCorp Inc.", IntPtr.Zero);
        }
    

    And refer to You cannot delete a file or a folder on an NTFS file system volume.