Directory.Delete Method

   
Directory.Delete Method

Class

System.IO.Directory

Syntax

 Directory.Delete(   path   [,   recursive   ]) 
path (required; String)

The path of the folder to delete.

recursive (optional; Boolean)

Indicates whether the folder and its contents are to be deleted if the folder is not empty. Its default value is False .

Return Value

None

Description

Removes or deletes an existing directory

Rules at a Glance

  • If path does not exist, the method generates a runtime error.

  • If recursive is set to False (its default value), the directory must be empty to be successfully deleted; otherwise , a runtime error will be generated.

  • If recursive is set to True , the method will delete not only the final directory in path , but also of its files and all of its subdirectories, as well as all nested subdirectories and nested files.

  • path can be either an absolute path (a complete path from the root directory to the directory whose existence is to be confirmed) or a relative path (starting from the current directory to the path whose existence is to be confirmed).

  • path can be either a path on the local system, the path of a mapped network drive, or a UNC path.

  • path cannot contain wildcard characters .

Programming Tips and Gotchas

  • The Delete method permanently deletes directories and their contents. It doesn't move them to the Recycle Bin.

  • Care must be taken when setting recursive to True due to the danger of accidentally removing files, especially since the method does not prompt whether it should delete any folders or files.

  • If the user has adequate rights, the source or destination can be a network path or share name . For example:

     Directory.Delete("\NTSERV1\d$\RootTwo") Directory.Delete("\RootTest") 
   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net