File Information
Imports System.IO
Imports System.Windows.Forms
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtDisplay = New System.Windows.Forms.TextBox
Me.cmdCreate = New System.Windows.Forms.Button
Me.cmdChangeDate = New System.Windows.Forms.Button
Me.cmdGetInfo = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
Me.txtDisplay.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtDisplay.Location = New System.Drawing.Point(9, 79)
Me.txtDisplay.Multiline = True
Me.txtDisplay.ReadOnly = True
Me.txtDisplay.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtDisplay.Size = New System.Drawing.Size(280, 168)
Me.txtDisplay.TabIndex = 9
'
Me.cmdCreate.Location = New System.Drawing.Point(9, 39)
Me.cmdCreate.Size = New System.Drawing.Size(88, 24)
Me.cmdCreate.TabIndex = 8
Me.cmdCreate.Text = "Create"
'
Me.cmdChangeDate.Location = New System.Drawing.Point(201, 39)
Me.cmdChangeDate.Size = New System.Drawing.Size(88, 24)
Me.cmdChangeDate.TabIndex = 7
Me.cmdChangeDate.Text = "Change Date"
'
Me.cmdGetInfo.Location = New System.Drawing.Point(105, 39)
Me.cmdGetInfo.Size = New System.Drawing.Size(88, 24)
Me.cmdGetInfo.TabIndex = 6
Me.cmdGetInfo.Text = "Get Info"
'
Me.TextBox1.Location = New System.Drawing.Point(9, 11)
Me.TextBox1.Size = New System.Drawing.Size(280, 21)
Me.TextBox1.TabIndex = 5
Me.TextBox1.Text = "c:\myfile.txt"
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(298, 259)
Me.Controls.Add(Me.txtDisplay)
Me.Controls.Add(Me.cmdCreate)
Me.Controls.Add(Me.cmdChangeDate)
Me.Controls.Add(Me.cmdGetInfo)
Me.Controls.Add(Me.TextBox1)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtDisplay As System.Windows.Forms.TextBox
Friend WithEvents cmdCreate As System.Windows.Forms.Button
Friend WithEvents cmdChangeDate As System.Windows.Forms.Button
Friend WithEvents cmdGetInfo As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Private Sub cmdCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreate.Click
Try
Dim MyFile As New FileInfo("c:\myfile.txt")
MyFile.Create().Close()
Out("File created.")
Catch err As Exception
Out(err.Message)
End Try
End Sub
Private Sub cmdGetInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetInfo.Click
Try
Dim MyFile As New FileInfo("c:\myfile.txt")
Out("Length in bytes: " & MyFile.Length)
Out("Attribute list: " & MyFile.Attributes.ToString)
Out("Stored in: " & MyFile.DirectoryName)
Out("Created: " & MyFile.CreationTime)
Catch err As Exception
Out(err.Message)
End Try
End Sub
Public Sub Out(ByVal NewText As String) ' Utility for displaying information.
txtDisplay.Text &= vbNewLine & NewText
txtDisplay.SelectionStart = txtDisplay.Text.Length - 1
txtDisplay.ScrollToCaret()
End Sub
Private Sub cmdChangeDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChangeDate.Click
Try
Dim MyFile As New FileInfo("c:\myfile.txt")
MyFile.LastWriteTime = DateTime.Today.Add(TimeSpan.FromDays(100))
Out("Time updated.")
Catch err As Exception
Out(err.Message)
End Try
End Sub
End Class
Related examples in the same category
1. | Delete *.Bak under a directory | | |
2. | Change file attribute for *.* | | |
3. | Get Files under an Directory and print its Full Name and Length | | |
4. | Find Hidden File under a directory | | |
5. | Update file create time, last access time and last write time | | |
6. | Get Invalid File Name Chars | | |
7. | Delete a file if exist | | |
8. | Is it a File or a Directory | | |
9. | File Time: created, last modified and accessed | | |
10. | English File Size | | |
11. | File Class Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. | | |
12. | File Class provides static methods for the creation, copying, deletion, moving, and opening of files | | |
13. | Open path in string to read | | |
14. | Create Text file with File.CreateText | | |
15. | File.AppendAllLines (String, IEnumerable(String)) appends lines to a file, and then closes the file. | | |
16. | File.AppendAllText opens a file, appends string to the file, and then closes the file. | | |
17. | File.AppendAllText appends string to the file, creating the file if it does not already exist. | | |
18. | File.AppendText creates a StreamWriter that appends UTF-8 encoded text to an existing file. | | |
19. | File.Copy copies an file to a new file. | | |
20. | File.Create creates or overwrites a file in the specified path. | | |
21. | File.Create creates or overwrites the specified file. | | |
22. | File.CreateText creates or opens a file for writing UTF-8 encoded text. | | |
23. | File.Decrypt decrypts a file that was encrypted using the Encrypt method. | | |
24. | File.Exists determines whether the specified file exists. | | |
25. | File.GetAccessControl gets a FileSecurity object that encapsulates the access control list (ACL) entries | | |
26. | File.GetAttributes gets the FileAttributes of the file on the path. | | |
27. | File.GetCreationTime returns the creation date and time of the specified file or directory. | | |
28. | File.GetLastAccessTime returns the date and time the specified file or directory was last accessed. | | |
29. | File.GetLastWriteTime returns the date and time the specified file or directory was last written to. | | |
30. | File.Move moves a specified file to a new location, providing the option to specify a new file name. | | |
31. | File.Open opens a FileStream on the specified path with read/write access. | | |
32. | File.Open opens a FileStream on the specified path, with the specified mode and access. | | |
33. | File.Open opens a FileStream on the specified path, with mode setting and sharing option. | | |
34. | File.OpenRead opens an existing file for reading. | | |
35. | File.OpenText opens an existing UTF-8 encoded text file for reading. | | |
36. | File.OpenWrite opens an existing file or creates a new file for writing. | | |
37. | File.ReadAllLines opens a text file, reads all lines of the file, and then closes the file. | | |
38. | File.ReadAllLines opens a file, reads all lines of the file with the specified encoding, and then closes the file. | | |
39. | File.ReadLines reads the lines of a file. | | |
40. | Use Linq to search and read files | | |
41. | File.Replace replaces the contents with the contents of another file | | |
42. | File.SetLastAccessTime sets the date and time the specified file was last accessed. | | |
43. | File.SetLastWriteTime sets the date and time that the specified file was last written to. | | |
44. | File.Exists Method tests whether the specified file exists. | | |
45. | File.GetAttributes Gets the FileAttributes of the file on the path. | | |