Visual C # As the next-generation mainstream program development language, the power of language functions is well known. And there is a very rich program development package - .NET Framework SDK as his back shield. This makes Visual C # have a stage that gives full play to their skills. The powerful feature of Visual C # not only manifests data processing in supporting various databases, but also features network programming and file processing.
The recycle bin of the window operating system is a protection measures for files. He is mainly a matter of action. In the new window 2000 system, when I delete the file into the recycle bin, press the "Empty Recycle Bin" button to clear the recycle bin. At this time, "a certain file is not empty, can not be deleted" Information. So I have to recover all, then in the folder to be deleted, first delete the file inside, then delete the folder, so that the recycle bin can be emptied. But this has brought troubles from our operating system. This article uses Visual C # to handle the powerful features of the file, use this software to empty the files to be deleted in the recycle station, and remove this trouble.
I. Main ideas of programming
We know that the window system is temporarily saved below the file information we will delete in the "C: / Recycled" directory. Thorough the file to be deleted in this directory through the "Clear Recycle Bin" button. The main idea of this program is based on the above knowledge. Specific description is as follows:
(1). First, determine whether the "Recycled" directory below the C drive is empty.
(2). If you don't empty, you will traverse all file information and delete the file.
Two. Program design and operational environment
(1). Window system 2000 professional version
(2) .. Net Framework SDK Beta 2
3. The main steps and specific explanations of programming (1). How to determine if the "Recycled" directory below the C drive is empty.
To determine if there is file information in the "C: / Recycled" directory, you have to go through two steps first to determine this directory. Second only can determine if this directory is empty. Here, follow these two steps to do specific introductions:
i>. How to find the "C: / Recycled" directory in the program.
A namespace --system.io is encapsulated in the .NET Framework SDK. There are many classes, objects, properties, and methods related to files and directory processing in this name space. Visual C # is a specific operation of files and directories by flexible calling these resources. This article is mainly used in two classes in this name: Directory class and File class. The former is mainly used in the program to handle and directory-related operations, such as determining file information in the directory and getting the directory. The latter is primarily used in the program to handle and file-related operations, such as deleting files. In the program, the GetFiles ("Directory Name") method in the Directory class is used. The return of this method is an enumeration type, which consists of a set of strings. The getFiles () method is to form a string in each file name in the directory and then form a enumeration type by these strings.
Ii>. Judging whether this directory is empty.
Here to introduce the Foreach statement, Visual C # is to collect enumerations through this statement. In this article, all deleted file information exists in "C: / Recycled" is here.
INT c = 0; // Define this variable is mainly to determine if there is a file for FOREACH in the directory (String S1 in Directory.GetFiles) // Returns the enumeration type when the file name character serial { C;} if (c> 0) // Determine if there is a file if c> 0 is recycled, there is no {... ..} (2). If the "c: / recycled" directory is not If you are empty, you will traverse all the file information in the directory and delete the file.
In this paragraph to introduce the usage of the Messagebox class. People who have used VB and Delphi must know how easy it is to show that the prompt information is in such a programming language. But in Visual C #, such operations are obviously relatively cumbersome, but there is a certain increase in flexibility. In Visual C #, the System.Windows.Forms namespace encapsulates a class of MessageBox, which has defined some methods related to display prompt information (SHOW methods), objects, and properties in this class. There is a specific introduction to the Messagebox class in this program.
To delete files on the disk, use the delete () method of the File class in the namespace system.io. The parameter behind the delete () method is the full path name of the disk where the file is located. To get the full path name of the file, use the Foreach statement, the program is the FOREACH statement to get the full path name of the file from a enumeration type containing all the file full path name. The specific implementation statement is as follows:
IF (c> 0) // Decision "C: / Recycled" directory exists {DialogResult r = messagebox.show ("Is it sure?", "garbage handling!", MessageBoxButtons.yesno, MessageBoxicon.question; / / Display "OK" and "Cancel" two buttons, the icon is displayed is a question mark. INT SS = (int) r; if (ss == 6) // Press the OK button {Foreach (String S in Directory.GetFiles) // Put the full path name { File.delete (s); // Delete this file}}}
3. The main steps and specific explanations of programming (1). How to determine if the "Recycled" directory below the C drive is empty.
To determine if there is file information in the "C: / Recycled" directory, you have to go through two steps first to determine this directory. Second only can determine if this directory is empty. Here, follow these two steps to do specific introductions:
i>. How to find the "C: / Recycled" directory in the program.
A namespace --system.io is encapsulated in the .NET Framework SDK. There are many classes, objects, properties, and methods related to files and directory processing in this name space. Visual C # is a specific operation of files and directories by flexible calling these resources. This article is mainly used in two classes in this name: Directory class and File class. The former is mainly used in the program to handle and directory-related operations, such as determining file information in the directory and getting the directory. The latter is primarily used in the program to handle and file-related operations, such as deleting files. In the program, the GetFiles ("Directory Name") method in the Directory class is used. The return of this method is an enumeration type, which consists of a set of strings. The getFiles () method is to form a string in each file name in the directory and then form a enumeration type by these strings. Ii>. Judging whether this directory is empty.
Here to introduce the Foreach statement, Visual C # is to collect enumerations through this statement. In this article, all deleted file information exists in "C: / Recycled" is here.
INT c = 0; // Define this variable is mainly to determine if there is a file for FOREACH in the directory (String S1 in Directory.GetFiles) // Returns the enumeration type when the file name character serial { C;} if (c> 0) // Determine if there is a file if c> 0 is recycled, and there is no {... ..}
(2). If you are not empty in the "C: / Recycled" directory, you will traverse all the file information in the directory and delete the file.
In this paragraph to introduce the usage of the Messagebox class. People who have used VB and Delphi must know how easy it is to show that the prompt information is in such a programming language. But in Visual C #, such operations are obviously relatively cumbersome, but there is a certain increase in flexibility. In Visual C #, the System.Windows.Forms namespace encapsulates a class of MessageBox, which has defined some methods related to display prompt information (SHOW methods), objects, and properties in this class. There is a specific introduction to the Messagebox class in this program.
To delete files on the disk, use the delete () method of the File class in the namespace system.io. The parameter behind the delete () method is the full path name of the disk where the file is located. To get the full path name of the file, use the Foreach statement, the program is the FOREACH statement to get the full path name of the file from a enumeration type containing all the file full path name. The specific implementation statement is as follows:
IF (c> 0) // Decision "C: / Recycled" directory exists {DialogResult r = messagebox.show ("Is it sure?", "garbage handling!", MessageBoxButtons.yesno, MessageBoxicon.question; / / Display "OK" and "Cancel" two buttons, the icon is displayed is a question mark. INT SS = (int) r; if (ss == 6) // Press the OK button {Foreach (String S in Directory.GetFiles) // Put the full path name { File.delete (s); // Delete this file}}}