Re: How to delete directory?

From: mscir (mscir_at_access4less.com.net.org.uk)
Date: 05/24/04


Date: Mon, 24 May 2004 00:29:08 -0700

Ken wrote:
> Hi All,
> How to delete directory with VB6?
> Thanks in advance!

I know of two ways, one is straight VB:

 From the help files:

RmDir Statement:
Removes an existing directory or folder.

Syntax:
RmDir path

The required path argument is a string expression that identifies the
directory or folder to be removed. The path may include the drive. If no
drive is specified, RmDir removes the directory or folder on the current
drive.

Remarks

An error occurs if you try to use RmDir on a directory or folder
containing files. Use the Kill statement to delete all files before
attempting to remove a directory or folder.

-------

Kill Statement Example:
This example uses the Kill statement to delete a file from a disk.

'Assume TESTFILE is a file containing some data.
Kill "TestFile" ' Delete file.

'Delete all *.TXT files in current directory.
Kill "*.TXT"

I think kill "path\*.*" deletes every file in the path.
Note: I think the files you kill can't be recovered from the recycle bin.

==================================

Or you can use the File System Object
(add a reference to Microsoft Scripting Runtime)

http://www.juicystudio.com/tutorial/vb/files.asp

Mike



Relevant Pages

  • Re: Cant Kill file?
    ... I originally had the code as SaveCopyAs, ... >you are closing) so the Kill statement never executes. ... >Excel Blog - Daily Dose of Excel ... >> am writing to the temporary folder. ...
    (microsoft.public.excel.misc)
  • Re: Using VB to rename and move files ?
    ... > name and location - may include directory or folder, ... String expression that specifies the new file ... > This example uses the Name statement to rename a file. ... > Kill Statement Example ...
    (comp.lang.basic.visual.misc)
  • Re: Using VB to rename and move files ?
    ... Renames a disk file, directory, or folder. ... String expression that specifies the new file ... This example uses the Name statement to rename a file. ... Kill Statement Example ...
    (comp.lang.basic.visual.misc)
  • Re: Delete folder
    ... If the directory is empty then RmDir works fine. ... If the directory has files then you need to Kill all ... The API has it is own error handling. ... > Is there any built-in function in VB6 that allows me to delete a folder on ...
    (microsoft.public.vb.general.discussion)
  • Re: Many File Import
    ... copy the files you want into a temporary folder and import them from ... there (with the Kill statement), ... >>Please respond in the newgroup and not by email. ...
    (microsoft.public.access.externaldata)