VB icon

Basic File Functions - Its Easy

Email
Submitted on: 1/1/2015 1:10:00 AM
By: Pankaj Nagar (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB.NET
Views: 2412
 
     File Manipulation Functions. No API
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Basic File Functions - Its Easy
// Description:File Manipulation Functions. No API
// By: Pankaj Nagar (from psc cd)
//
// Returns:Depends
//**************************************

Basic File Functions
---------------------
Read File:
----------
Imports System
Imports System.IO
Public Module modmain
Sub Main()
 Dim srFile as StreamReader = File.OpenText("C:\autoexec.bat")
 Console.WriteLine(srFile.ReadToEnd())
 srFile.Close
End Sub
End Module
Write File:
-----------
Imports System
Imports System.IO
Public Module modmain
Sub Main()
 Dim swFile as StreamWriter = File.CreateText("C:\test.txt")
 swFile.WriteLine("Hello World ;)")
 swFile.Flush()
 swFile.Close()
End Sub
End Module
File Version Info:
------------------
Imports System
Imports System.Diagnostics
Public Module modmain
Sub Main()
 Dim versionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo("C:\WINNT\Notepad.exe")
 Console.WriteLine("Notepad version " + versionInfo.FileVersion)
 Console.WriteLine("Description: " + versionInfo.FileDescription)
End Sub
End Module
File Size:
----------
Imports System
Imports System.IO
Public Module modmain
Sub Main()
 Dim MyFile as new FileInfo ("c:\autoexec.bat")
 Console.WriteLine("The length of autoexec.bat is " _
 + MyFile.Length.ToString + " bytes.")
End Sub
End Module
Copy Move and Delete File:
--------------------------
Imports System
Imports System.IO
Public Module modmain
Sub Main()
 	File.Copy("c:\autoexec.bat", "c:\autocopy.ext")
 	File.Move("c:\autocopy.ext", "c:\newname.ext")
	File.Delete("c:\autocopy.ext")	
End Sub
End Module
Temporary File Name:
---------------------
The GetTempFileName function creates a name for a temporary file. The filename is the concatenation of specified path and prefix strings, a hexadecimal string formed from a specified integer, and the .TMP extension.
Imports System
Imports System.IO
Public Module modmain
Sub Main()
 Console.WriteLine(Path.GetTempFileName)
End Sub
End Module


Other 8 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.