I'm trying to create a directory using the URL form of path
\\server\share\folder
but getting exceptions:
C:\Apps\nim-1.6.0\lib\pure\os.nim(2552) createDir
C:\Apps\nim-1.6.0\lib\pure\os.nim(2522) existsOrCreateDir
C:\Apps\nim-1.6.0\lib\pure\os.nim(2507) rawCreateDir
C:\Apps\nim-1.6.0\lib\pure\includes\oserr.nim(95) raiseOSError
Error: unhandled exception: The specified path is invalid.
If I try to create the directory from a command prompt using md it works fine. If I use a mapped drive, say X: = \ \server\share, it works fine"
There is probably a simple reason but I'm not finding a solution. Any help would be appreciated.
sample trial code:
import std/os
# this doesn't work
let testFldr = "\\\\<server>\\<share>\\test1"
# this works
# let testFldr = "X:\\test1"
createDir(testFldr)
echo testFldr & " created"
quit(0)
from a command prompt (same shell session as the above is executed in), this works
md \\<server>\<share>\test1
You are using characters that are not valid as path name: https://stackoverflow.com/a/31976060
As you can see way more characters are invalid on windows then linux:
< (less than)
> (greater than)
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
Hmm, thanks but not seeing your point. The backslashes are valid Windows path separators, not part of the directory names themselves. They are doubled in the strings vars code as they need to be escaped.
The Nim function dirExists("\\<server>\<share>") works just fine and finds the path. I'm starting to think there is something going on in the kernel32 call Nim is making to createDirectoryW.
No idea whats wrong with std/os but this works:
import std/winlean
let testFldr = "\\\\KHANDESKW\\Shared\\helloworld"
let ws = newWideCString(testFldr)
let r = createDirectoryW(ws,nil)
if r != 0:
echo testFldr & " created"
else:
echo "Error"
Yep, works with std/winlean as suggested. Thanks!
Interesting. Probably should report as a bug for std/os...