In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the use of VB.NET System.IO, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Get to know VB.NET System.IO
The file-related classes in VB.NET are concentrated in the large class VB.NET System.IO, in which we can see many class names that start with "File". Let's introduce a few commonly used classes, which are:
◆ Directory: static methods for creating, moving, and enumerating directories and subdirectories.
◆ File: static methods for creating, copying, deleting, moving, and opening files, and assisting in the creation of FileStream objects.
◆ FileInfo: provides instance methods for creating, copying, deleting, moving, and opening files, and helps create FileStream objects.
◆ FileStream: work with the Stream object to complete more file operations. We will introduce it in the next section.
◆ Path: specifies the directory path information for the file.
In the following program snippet, we will use the above-mentioned classes and the most commonly used "File Open" dialog window to complete a file-based programming. Program function: move files to the Recycle Bin folder and run these programs from the Recycle Bin.
Many readers may ask, why take this code as an example? There are three reasons:
1. This code fits the content of this section.
two。 Many virus programs were placed in the Recycle Bin at the beginning of Windows's release, and these technologies are sure to increase readers' interest in learning this article.
3. This procedure still has certain practicability. If you have an important file, you can Copy it to the Recycle Bin.
Who would have thought of saving files in the recycling bin? And for the average user, they will not know that the Recycle Bin can save and run the file, because double-clicking the file in the Recycle Bin will not run, only its file properties will be displayed. Even if you open the Recycle Bin, you can only see the files to be deleted, but not the files we specially saved to the Recycle Bin.
Add controls and set related properties: three Button, one LISTBOX, and one OPENFILEDIALOG control.
VB.NET System.IO code
Double-click Button1 to add the following code with detailed comments in the code:
Private Sub Button1_Click ByVal sender As System.Object
ByVal e As System.EventArgs Handles Button1.Click
OpenFileDialog1.ShowDialog
'Show the file open dialog box
Dim fname As New FileInfo OpenFileDialog1.FileName
'initialize the FILEINFO class, which can get all kinds of information about the file, which is used to get the file name in this code
Dim copyf As System.IO.File
'initialize the FILE class, which is used to perform specific operations on the file. This code is used to transfer the file.
Sname = fname.Name
'use the name property of the fileinfo class to get the file name, but not the path
Copyf.Move OpenFileDialog1.FileName
'move to the Recycle Bin folder, where RECYCLED is the Recycle Bin folder
End Sub
Double-click Button2 to add the following code with detailed comments in the code:
Private Sub Button2_Click ByVal sender As Object
ByVal e As System.EventArgs Handles Button2.Click
Dim zh
Dim pj As String
'Select the file to run in the listbox control
Zh = ListBox1.SelectedIndex
'record the selected serial number with zh
Pj = ListBox1.Items.Item zh
'record the text corresponding to the serial number in pj, and the corresponding text in this code represents the file name
Me.Text = "running program" + pj
'indicates the running programs in the window title bar, which are listed in listbox, that is, the files in the Recycle Bin
Dim spros As New System.Diagnostics.Process
'Process is a process class, which is similar to the shell function in Visual Basic6.0 in Visual Basic .net
We will discuss it specifically in a later article.
Spros.Start pj
'run the selected file using the start property in the Process class
End Sub
Double-click to add the following code to Button3 with detailed comments in the code:
Private Sub Button3_Click ByVal sender As Object
ByVal e As System.EventArgs Handles Button3.Click
Dim dir As System.IO.Directory
Because the directory object can directly operate the directory, use it here to get the number of recycled files
Dim i As Integer
Dim filename fileno
ListBox1.Items.Clear
'empty the listbox to prepare for the next display
Filename = dir.GetFiles "c \ recycled""
'get an array of files using the Getfile attribute of the Directory class
Fileno = dir.GetFiles "c \ recycled"" .length
'use Length to get the size of the array, that is, how many files are in the Recycle Bin
For I = 0 To fileno-1
ListBox1.Items.Add filename i
'add each file to the listbox to display the specific files in the Recycle Bin
Next
End Sub
Program description: if you want to run a file, please select a file first, and then click the "start File from the Recycle Bin" button. In the display of the Recycle Bin files, you will see some strange file names, these files are the files you deleted, but Microsoft has changed the original names of these files. So you don't have to worry about these files, but these files can still be set up and run in this program, the same as the files you save in the Recycle Bin except for their names. Note that when you open the Recycle Bin in my computer and Explorer and select empty Recycle Bin, all files in the Recycle Bin will be deleted.
Thank you for reading this article carefully. I hope the article "what's the use of VB.NET System.IO" shared by the editor will be helpful to everyone? at the same time, I also hope that you will support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.