1

In ubuntu I've created a share. On windows I mounted this share to Y using:

mount -o nolock \\192.168.2.44/mnt/shared Y:

Next, I want to use a dotnet core application to create directories in this share. This application should support any character supported by the NFS share folder.

static void Main(string[] args)
{
    // works if Y: is NFS 
    Directory.CreateDirectory("Y:/subdir/:"); // works!
    Directory.CreateDirectory("Y:/:"); // works!
    // Directory.CreateDirectory("Y:/**"); // Does not work 
    // Directory.CreateDirectory("Y:/?"); // Does not work
    try
    {
        Directory.CreateDirectory("C:/:"); // NTFS
    } catch (Exception e)
    {
        Console.WriteLine("Not NFS"); // ntfs does not work (as expected)
    }
}

The above code works as expected; if I want to create a directory ":" the program allows this on the NFS share but not on the NTFS drive.

I expect this to behave the same for directories ** and ?. But if I comment out these lines of code I get an error. enter image description here

Anyone knows how I can create special-character dictionaries in dotnet core 2.2?

Things I've already tried

I tried to use the unicode of questionmark

Directory.CreateDirectory("Y:/\u003F");

But this results in the same error.


This question is NOT the same as What characters are forbidden in Windows and Linux directory names? because: The above question asks what the forbidden characters are in windows and linux file directories. My question is about how to get around those windows restrictions when you want to write to a linux directory from windows.

Hedgelot
  • 146
  • 5
  • i didnt test i m on mobile but you can try: `Directory.CreateDirectory(@"Y:/?");` Are you sure windwos will even let you do ths before you try doing this with c#? – Denis Schaf Jul 04 '19 at 15:12
  • 1
    @DenisSchaf What exactly makes you think adding a `@` would make any difference? There's no character to escape in that string. – Camilo Terevinto Jul 04 '19 at 15:13
  • pure hope i guess? :D I mean as far as i am aware windows wont let you have any characters like `” * : < > ? / \ |` in foldernames so this is probably not going to work anyway – Denis Schaf Jul 04 '19 at 15:14
  • @DenisSchaf I just tried it, unfortunately it didn't work. I was slightly hoping for `@"Y:/\u003F"` but that will ofcourse just give a dictionary named "u003F". If I create a dictionary using windows explorer, then yes, it won't let me make folders in Y:/ with these characters. But I was hoping that dotnet core could do it. And it actually works with the : character, so I don't understand why others won't work. – Hedgelot Jul 04 '19 at 17:01
  • 1
    Why dont you just stick to legal names? Whats the point of having * or ? In a folder name? – Denis Schaf Jul 04 '19 at 17:07
  • Possible duplicate of [What characters are forbidden in Windows and Linux directory names?](https://stackoverflow.com/q/1976007/608639), [Invalid characters in a filename on Windows?](https://stackoverflow.com/q/11721147/608639), etc. – jww Jul 04 '19 at 17:16

2 Answers2

0

You need an ASCII mapping file (ascii_mappings) on your NFS server that translates the characters you want to name your files with, for legal characters for NTFS file system.

This are illegal on NTFS:

" : < > \ * / ? |

JC Hernández
  • 777
  • 3
  • 13
0

Seems like the answer to my question is: Not possible when running on Windows.

The code actually works fine on Linux.

I've tried in multiple languages but the error I receive seems to be an error from Windows, which does not support these characters at all even if the file system supports it. According to What characters are forbidden in Windows and Linux directory names? the ":" character sometimes works in NTFS, so I suppose that's the only character that gets a proper check if it's supported by the file system.

Hopefully Windows will get proper NFS support in the future. In the meantime, if you really need those characters, the best fix is to simply run the program on Linux.

Hedgelot
  • 146
  • 5