Re: [BLACKBOX] Deleting a directory

From: [at]} <Chris>
Date: Fri, 10 Dec 2010 09:31:45 +1030

----boundary-LibPST-iamunique-653925165_-_-
Content-type: text/plain

>-----Original Message-----
>From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
>Sent: Friday, 10 December 2010 8:31 AM
>To: BLACKBOX{([at]})nowhere.xy
>Subject: [BLACKBOX] Deleting a directory
>
>Hi,
>
>I'm sure I've done this before, but have forgotten how (and where)!
>
>
>To delete a File one calls
>
> Files.dir.Delete (loc, name$)
>
>but how do you delete a directory?
>

One way you can do it is with a direct call to the Windows API:

  PROCEDURE DeleteDir*(IN name: ARRAY OF CHAR): BOOLEAN;
  BEGIN
    RETURN WinApi.RemoveDirectory(WinStr(name)) # 0
  END DeleteDir;

DeleteDir returns TRUE if the directory could be deleted (i.e. if it is
empty, has delete permissions etc.)

The tricky part is that the RemoveDirectory function requires a parameter of
type WinApi.PtrSTR. The following function returns a WinApi.PtrSTR given an
ARRAY OF CHAR. There might be a better way but it seems to work:

  PROCEDURE WinStr(IN x: ARRAY OF CHAR): WinApi.PtrSTR;
  VAR
    p: POINTER TO ARRAY OF SHORTCHAR;
  BEGIN
    NEW(p, LEN(x$) + 1);
    p^ := SHORT(x$);
    RETURN p^
  END WinStr;

Regards,
Chris

Chris Burrows
CFB Software
http://www.cfbsoftware.com


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-653925165_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3Vy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ib2R5ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNU
Uy5PQkVST04uQ0hcfX0AQExJ
----boundary-LibPST-iamunique-653925165_-_---
Received on Fri Dec 10 2010 - 00:01:45 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:27 UTC