2007-09-25

FileInfo Class

Use the FileInfo class for typical operations such as copying, moving, renaming, creating, opening, deleting, and appending to files

Many of the FileInfo methods return other I/O types when you create or open files. You can use these other types to further manipulate a file. For more information, see specific FileInfo members such as Open, OpenRead, OpenText, CreateText, or Create.

Sample Code

Class FileManagement
Private m_pFile As IO.FileInfo
Private m_sTempFile As String = "C:\Test.Txt"


Public Sub SampleCreateFile()
m_pFile = New IO.FileInfo(m_sTempFile)

' Check exist file name
If Not m_pFile.Exists Then
Dim objStream As IO.StreamWriter = m_pFile.CreateText()

objStream.WriteLine("Welcome to My Blog")
objStream.WriteLine("Thank you")

objStream.Flush()
objStream.Close()
objStream.Dispose()
End If

End Sub

Public Sub SampleReadFile()
m_pFile = New IO.FileInfo(m_sTempFile)

If m_pFile.Exists Then
'Read Text
Dim objStream As IO.StreamReader = m_pFile.OpenText()

' Peek returns the next aviable charactor
While objStream.Peek() >= 0
Console.WriteLine(objStream.ReadLine)
End While

End If
End Sub

Public Sub SampleFileInfomation()

' Use class file to get file attributes

' Get Time
Console.WriteLine(IO.File.GetCreationTime(Me.m_sTempFile).ToLongTimeString())
Console.WriteLine(IO.File.GetLastAccessTime(Me.m_sTempFile).ToLongTimeString())
Console.WriteLine(IO.File.GetLastWriteTime(Me.m_sTempFile).ToLongTimeString())


' Set Time a
IO.File.SetCreationTime(m_sTempFile, DateTime.Now)
IO.File.SetLastAccessTime(m_sTempFile, DateTime.Now)
IO.File.SetLastWriteTime(m_sTempFile, DateTime.Now)

End Sub

Public Sub SampleOther()
m_pFile = New IO.FileInfo(m_sTempFile)

' Copy File
m_pFile.CopyTo("C:\test2.txt", True)

' Move File
m_pFile.MoveTo("C:\testMove.txt")

' Delete
m_pFile = New IO.FileInfo("C:\test2.txt")
m_pFile.Delete()
End Sub
End Class

5 comments:

Anonymous said...

Usted ha hecho algunos comentarios agradables allí. Hice una búsqueda sobre el tema y que se encuentran sobre todo la gente con tu consentimiento.

Anonymous said...

Just want to say what a great blog you got here!I’ve been around for quite a lot of time, but finally decided to show my appreciation of your work! Thumbs up, and keep it going!

Anonymous said...

What i find troublesome is to discover a blog that may seize me for a minute however your weblog is different. Bravo.

Anonymous said...

Sоmetimes a little rеsolutiοn cаn get intο the batteгy on
the conneсtіon stage. Ӏ uѕually
gіνe it a quicκ eliminate ωith a little
bit оf tissue then onе nаrroω but blunt suсh аs a ѕtraw also it
does the technique foг me. I'd imagine a dry cotton marijuana would work as well, but that is the cause of the charged electric battery not working.

Here is my web-site Green Smoke Coupon

Anonymous said...

Excellent product with Great Pгices, Thanks.

Tаκe a look at my site green smoke coupon