In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to reflect the role of VB.NET System.IO in actual programming. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
In program development, the text of the file is often operated accordingly. The use of VB.NET programming language for program development, will help us easily achieve a variety of file operations. First of all, let's take a look at a related VB.NET System.IO-like application.
File manipulation is an indispensable task in software development. I remember that the author took a lot of trouble when learning the programming of Visual Basic6.0 file operation. But now with .net, it greatly simplifies the difficulty of development and learning, so that beginners can master file-related programming skills in a very short time.
Get to know VB.NET System.IO
The file-related classes in .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.
Task
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.
The application code of VB.NET System.IO is as follows
The code is written by VB.NET.
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?OpenFil eDialog1.FileName?' Initialize the FILEINFO class, which can get all kinds of information about the file. In this code, it is used to get the file name Dim copyf As System.IO.File''initialization FILE class. This class is used to perform specific operations on the file. In this code, it is used to transfer the file sname = fname.Name??''. Use the name property of the fileinfo class to get the file name, but does not include the path copyf.Move?OpenFileDialog1.FileName? "c?\ recycled\" & sname? '' move to the Recycle Bin folder. RECYCLED is the Recycle Bin folder End Sub
Double-click Button2 to add the following code, with detailed comments in the VB.NET System.IO 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' records the selected serial number with zh
Pj = ListBox1.Items.Item?zh?
'' use pj to record the text corresponding to the serial number, 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 all listed in listbox
That is, files in the Recycle Bin
Dim spros As New System.Diagnostics.Process??
'' Process is a process class, in Visual Basic .net
Similar to the shell function in Visual Basic6.0
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''since the directory object can directly operate on the directory, use it here to get the number of recycled files Dim i As Integer Dim filename? Fileno ListBox1.Items.Clear?? 'clear listbox to prepare for the next display filename = dir.GetFiles? "c?\ recycled"? "? '' use the Getfile attribute of the Directory class to get the file array fileno = dir.GetFiles? "c?\ recycled"? "? .length'. Use Length to obtain 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 listbox to display the specific file Next End Sub in the Recycle Bin
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.
In addition, VB.NET System.IO 's application saves the moved files in the Recycle Bin in disk C. if you want to save to the Recycle Bin in another disk, please change the drive letter to the appropriate disk name. Such as: d:\ F?\ etc.
The above is the editor for you to share how to reflect the role of VB.NET System.IO in the actual programming, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.