-3

Context: Synology NAS Linux accessed by Windows 7 using a

Problem: Windows refuses the creation of a directory which name begins with an "@" (at-sign / at sign).

Unfortunately, I have to create a directory named @eaDir (hi, Synology Photo Station users!) within a Python script that I want to execute on Windows.

The following line raises an error when executed from an "cmd" console.

os.mkdir("@eaDir")

FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable (cannot find specified file)

The same error occurs with mkdir in the DOS shell or when giving the final directory name "@eaDir" after creating a new directory from Windows Explorer...

Does anyone have an idea about how to achieve the creation of directory with an @ at sign at the beginning in a Python script executed on Windows?

Note: thanks to all contributors who helped in identifying the root cause of the error.

LucRhan
  • 1
  • 2
  • 1
    What error does it raise? – Scott Hunter May 08 '17 at 11:03
  • 1
    DOS has not existed for a considerable period of time. @ is not a special character in Windows NTFS/FAT. Typing `os.mkdir("@eaDir")` at the command prompt wont run the python command. What specifically are you doing, how, and what error do you encounter? – Alex K. May 08 '17 at 11:03
  • The console is not cmd.exe; that's a shell that can use the console, but it's not responsible for the console. That's conhost.exe. Also, `os.mkdir` also has nothing to do with cmd.exe. That's implemented by calling WinAPI `CreateDirectory`, and as noted above "@" is not a reserved character in Windows file systems. Control characters (ordinals 1-31) are reserved as well as the 5 wildcard characters and pipe (*?<>" and |), plus obviously the path separators backslash and slash. – Eryk Sun May 08 '17 at 11:10
  • @eryksun in fact, I am using a cmd.exe shell to execute my python script instead of python shell. With a python shell, the same instrcution works fine. – LucRhan May 08 '17 at 11:41
  • The only difference would be either the working directory since you're not specifying an absolute path and the version of Python run in either case, though the Python version really shouldn't be a factor here. Anyway, the cmd shell has nothing to do with this, and neither does the console. Getting `ERROR_FILE_NOT_FOUND` for a `CreateDirectory` call is weird. Is this on your system drive using NTFS, or another drive using some other file system? – Eryk Sun May 08 '17 at 12:02
  • From my Windows 7 cmd console, I change directory to my NAS (synology linux) which has actually another file system (ext4). I do have the same problem with python shell >>> os.chdir("w:/_Photos") >>> os.getcwd() 'w:\\_Photos' >>> os.mkdir("@eaDir") Traceback (most recent call last): File "", line 1, in os.mkdir("@eaDir") FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable: '@eaDir' >>> – LucRhan May 08 '17 at 12:15
  • That's probably a mapped drive for a UNC path of a file system redirector (local or network). File system drivers that aren't written by Microsoft are pretty bad in terms of the error codes they return (case in point: VirtualBox's VBoxSF file system). There are primarily 3 kernel status codes that can lead to `ERROR_FILE_NOT_FOUND`. Two are rarely seen (`STATUS_NO_SUCH_DEVICE` and `STATUS_NO_SUCH_FILE`) and the third is common `STATUS_OBJECT_NAME_NOT_FOUND` -- but not in the context of creating a directory. I don't know what it means here or if maybe something was just lost in translation. – Eryk Sun May 08 '17 at 12:27
  • 1
    It sounds like your NAS is refusing to create the directory, and this has nothing to with Windows, Python or cmd.exe. – Ross Ridge May 08 '17 at 17:33

1 Answers1

0

This works just fine on Windows 7:

C:\> python.exe -c "import os; os.mkdir('@test')"
handle
  • 5,859
  • 3
  • 54
  • 82
  • >python.exe -c "import os; os.mkdir('@eaDir')" Traceback (most recent call last): File "", line 1, in FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable: '@eaDir' – LucRhan May 08 '17 at 11:34
  • Sorry, don't know. It's not a permission error (5) and it doesn't already exist (183). Are you running this on a network share? – handle May 08 '17 at 11:41
  • kudos, I am running this on a network share (linux synology NAS). The instruction works fine with a local directory context... – LucRhan May 08 '17 at 12:04
  • Thank you. I will look into UNC path. Changing the working directory (if that's what cwd means) doesn't solve the issue. Python shell >>> os.chdir("w:/_Photos") >>> os.getcwd() 'w:\_Photos' >>> os.mkdir("@eaDir") Traceback (most recent call last): File "", line 1, in os.mkdir("@eaDir") FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable: '@eaDir' – LucRhan May 08 '17 at 12:21