File Handling Methods in VB.NET

Abhisek
Posted by in VB.NET category on for Beginner level | Views : 9925 red flag

This article gives description about different file handling methods present in VB.NET.


Various methods of file handling in VB.NET is given below,

1.Kill(File name with path):-

      This method deletes the said file/files from the disk. The name of the file to be deleted is passed to this method as string type arguments. Files are simply deleted and not moved to recycle-bin. The use of wild card(* and /) is permitted in this function.

Kill("C:\Files\abc.txt") This will delete the file abc.txt locates in C:\Files\

Kill("C:\Files\*.txt") This will delete all the files with .txt extension from C:\Files\

2.FileDateTime(file name with path):-

    This function returns the date and time of creation of the said file. The name of the file to be deleted is passed to this method as string type arguments.

Debug.WriteLine("Date &Time:"&(FileDateTime("C:\Files\abc.txt")))

This may display the the following output in Debug window.

Date & Time: 29/10/2009 09:54:34AM

3.FileLen(file name with path):-

    This method returns the size of the specified file in bytes.The name of the file to be deleted is passed to this method as string type arguments.
Debug.WriteLine("Size of file:"&(FileLen("C:\Files\abc.txt"))) 

This may return the following line in Debug window

Size of file:106

4.MKDir(folder name with path):-

   It creates a new folder(s) in the specified location.

MKDir("C:\Files\MyFile") After execution it will create a new folder MyFile.


5.RmDir(folder name with path):-

   This method delets the folder specified.
RmDir("C:\Files\MyFile") It will remove the folder MyFolder.


6.Dir(file name with path):-

   This method is used to check if the specified file is present or not.

StrCheck = Dir("C:\Files\abc.txt")
If StrCheck = "abc.txt" Then
Debug.WriteLine("File is present")
Else
Debug.WriteLine("File is not present")
EndIf
If the file exists the after execution it will display 'File is present' in debug window.

There are many more methods. I have included the most commonly used methods.


Page copy protected against web site content infringement by Copyscape

About the Author

Abhisek
Full Name: Abhisek Panda
Member Level: Bronze
Member Status: Member
Member Since: 10/11/2009 6:25:59 AM
Country: India
Abhisek Panda

Thanks and Regards Abhisek Panda Go Green And Save Your Future

Login to vote for this post.

Comments or Responses

Posted by: Anu4you007 on: 12/17/2009
Good article.

Login to post response

Comment using Facebook(Author doesn't get notification)