Files and Folders

Folder Operations

There are also VB functions that allow you to rename, create and remove directories (called folders in Win 95/98). These are:

Name

Description

MkDir

Creates a directory

RmDir

Removes a directory

Name

Renames a directory

To create a directory, you use the MkDir function:

MkDir DirNameandPath

So,

MkDir "C:\testdir"

creates the directory testdir (so long as it does not already exist)

To remove a directory, you use the RmDir function:

RmDir DirNameandPath

So,

RmDir "C:\testdir"

removes the directory testdir (so long as it is empty)

To rename a directory, you use the Name Function:

Name OldNameandPath As NewNameandPath

So,

Name "C:\testdir" As "C:\testdir2"

Renames testdir as testdir2.

If you want to know how to do these operations using Win API, which allows you to send files to the recycle bin, and display the standard file copying dialog, click here.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay