VB.NET-INFORMATIONS.COM



VB.NET Files Tutorials

How to VB.NET Directory operations

How to VB.NET Directory operations

Using Directory class , we can create , delete , move etc. operations in VB.NET. Because of the static nature of Directory class , we do not have to instantiate the class. We can call the methods in the class directly from the Directory class.

How to create a directory ?

In order to create a new directory , we can call CreateDirectory directly from Directory class.

Syntax : Directory.CreateDirectory(DirPath)

DirPath : The name of the new directory

VB.NET : Directory.CreateDirectory("c:\testdir")

How to check a directory exist or not ?

Before we creating a directory , we usually check that directory exist or not. For that we are using the Exists method in the Directory class.

Syntax : Directory.Exists(DirPath) as Boolean

DirPath : The name of the directory

Boolean : Returns true or false , if directory exist it Returns true , else it Returns false

VB.NET : Directory.Exists("c:\testdir")

How to move a Directory ?

If we want to move a directory and its contents from one location to another , we can use the Move method in the Directory class.

Syntax : Move(sourceDirName,destDirName)

sourceDirName : The source directory we want to move.

destDirName : The destinations directory name.

VB.NET : Directory.Move("c:\testdir1\testdir2", "c:\testdir")

How to delete a Directory ?

When we want to delete a directory we can use the Delete method in the Directory class

Syntax : Delete(DirPath)

DirPath : The Directory we want to delete.

VB.NET : Directory.Delete("c:\testdir1")

The following VB.NET source code shows these operations :

VB.NET Source Code


When you executing this program you can see , first it create directory testDir1 and then testDir2 is creating inside testDir1 , Next the program move the testDir2 to testDir . Finally it delete the directory testDir1. After the execution you can see testDir in c:\

VB.NET Files Related Contents
How to VB.NET File operations
How to VB.NET FileStream
How to VB.NET TextReader
How to VB.NET Simple TextReader
How to VB.NET TextWriter
How to VB.NET BinaryReader
How to VB.NET BinaryWriter

VB.NET Related Tpoics
Microsoft .Net Framework Tutorials
VB.NET Language Basics Tutorials
VB.NET Program Flow Control Tutorials
VB.NET Collections Tutorials
VB.NET String Tutorials
VB.NET Files Tutorials
VB.NET Excel 2007 Tutorials
VB.NET Crystal Reports Tutorials
VB.NET Communications Tutorial
VB.NET ADO.NET Tutorial with source code
ADO.NET Data Providers help and Tutorial
VB.NET ADO.NET Dataset Tutorial
ADO.NET DataAdapter and Dataset
VB.NET ADO.NET DataView Tutorial

Search here for more Vb.Net Source Code :


   Categories

    HOME
    VB.NET

 
 
 
   













  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2008 All Rights Reserved