digitalmars.D.learn - mkdir; remove; under Windows throw Exception
- unDEFER (14/14) Dec 09 2016 Hello!
- SonicFreak94 (2/3) Dec 09 2016 Try rmdir instead.
- unDEFER (2/5) Dec 09 2016 But it works under Linux
- Adam D. Ruppe (12/13) Dec 09 2016 That's just because the underlying C function handles the case.
- unDEFER (4/17) Dec 09 2016 Thank you, but I think in this case D must use unlink for
- Jonathan M Davis via Digitalmars-d-learn (9/23) Dec 09 2016 Well, much as I'd love to rag on Windows for doing dumb and annoying stu...
- unDEFER (6/16) Dec 09 2016 man remove:
- ag0aep6g (3/7) Dec 10 2016 D has no obligation to follow C in function naming.
- unDEFER (2/7) Dec 10 2016 I know, but why it works in Linux by Linux documentation?
- Adam D. Ruppe (4/5) Dec 10 2016 Coincidence. That detail is undefined in the D documentation
- unDEFER (3/8) Dec 10 2016 OH, OK. Undocumented behavior is undocumented behavior...
Hello! $ cat try.d import std.file; void main () { mkdir("D:\\TEST"); remove("D:\\TEST"); } $ ./try.exe std.file.FileException std\file.d(731): D:\TEST: Access Denied. ---------------- .... What I don't know about removing directories in Windows? Why I can't remove directory which just time created?
Dec 09 2016
On Saturday, 10 December 2016 at 01:19:45 UTC, unDEFER wrote:remove("D:\\TEST");Try rmdir instead.
Dec 09 2016
On Saturday, 10 December 2016 at 01:28:13 UTC, SonicFreak94 wrote:On Saturday, 10 December 2016 at 01:19:45 UTC, unDEFER wrote:But it works under Linuxremove("D:\\TEST");Try rmdir instead.
Dec 09 2016
On Saturday, 10 December 2016 at 03:29:18 UTC, unDEFER wrote:But it works under LinuxThat's just because the underlying C function handles the case. But the D function makes no promises about that: std.file.remove's documentation says "removes the file", leaving what it does to directories undefined. Interestingly, the Linux kernel *does* make the distinction: the C remove function on Linux does a test then calls unlink or rmdir based on if it is a directory or not. But it didn't always do that. But what you have is undefined behavior - the function is only guaranteed to work on files, and does not specify if it will work or be an error on directories.
Dec 09 2016
On Saturday, 10 December 2016 at 03:36:11 UTC, Adam D. Ruppe wrote:On Saturday, 10 December 2016 at 03:29:18 UTC, unDEFER wrote:Thank you, but I think in this case D must use unlink for implementation remove.But it works under LinuxThat's just because the underlying C function handles the case. But the D function makes no promises about that: std.file.remove's documentation says "removes the file", leaving what it does to directories undefined. Interestingly, the Linux kernel *does* make the distinction: the C remove function on Linux does a test then calls unlink or rmdir based on if it is a directory or not. But it didn't always do that. But what you have is undefined behavior - the function is only guaranteed to work on files, and does not specify if it will work or be an error on directories.
Dec 09 2016
On Saturday, December 10, 2016 01:19:45 unDEFER via Digitalmars-d-learn wrote:Hello! $ cat try.d import std.file; void main () { mkdir("D:\\TEST"); remove("D:\\TEST"); } $ ./try.exe std.file.FileException std\file.d(731): D:\TEST: Access Denied. ---------------- .... What I don't know about removing directories in Windows? Why I can't remove directory which just time created?Well, much as I'd love to rag on Windows for doing dumb and annoying stuff with file locks (which they do do), in this case, your code wouldn't have worked an other OSes either. The problem is that you created a directory and then used a function which removes files. If you want to remove a directory, then use rmdir (or rmdirRecurse if you want to blow away a non-empty directory). - Jonathan M Davis
Dec 09 2016
On Saturday, 10 December 2016 at 01:30:52 UTC, Jonathan M Davis wrote:On Saturday, December 10, 2016 01:19:45 unDEFER via Digitalmars-d-learn wrote: Well, much as I'd love to rag on Windows for doing dumb and annoying stuff with file locks (which they do do), in this case, your code wouldn't have worked an other OSes either. The problem is that you created a directory and then used a function which removes files. If you want to remove a directory, then use rmdir (or rmdirRecurse if you want to blow away a non-empty directory). - Jonathan M Davisman remove: remove - remove a file or directory The function which removes only files named unlink. The D must guarantee the same behaviour of remove on all OSes.
Dec 09 2016
On 12/10/2016 04:39 AM, unDEFER wrote:man remove: remove - remove a file or directoryThat's documentation for C, not for D.The function which removes only files named unlink. The D must guarantee the same behaviour of remove on all OSes.D has no obligation to follow C in function naming.
Dec 10 2016
On Saturday, 10 December 2016 at 14:10:15 UTC, ag0aep6g wrote:On 12/10/2016 04:39 AM, unDEFER wrote:I know, but why it works in Linux by Linux documentation?man remove: remove - remove a file or directoryThat's documentation for C, not for D.
Dec 10 2016
On Saturday, 10 December 2016 at 18:09:43 UTC, unDEFER wrote:I know, but why it works in Linux by Linux documentation?Coincidence. That detail is undefined in the D documentation which means the implementation is free to do whatever is easier for it in a platform-specific manner.
Dec 10 2016
On Saturday, 10 December 2016 at 18:30:53 UTC, Adam D. Ruppe wrote:On Saturday, 10 December 2016 at 18:09:43 UTC, unDEFER wrote:OH, OK. Undocumented behavior is undocumented behavior...I know, but why it works in Linux by Linux documentation?Coincidence. That detail is undefined in the D documentation which means the implementation is free to do whatever is easier for it in a platform-specific manner.
Dec 10 2016