mkdir; remove; under Windows throw Exception

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 9 17:30:52 PST 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 at 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



More information about the Digitalmars-d-learn mailing list