) Use Visual C # To clear the recycle bin.

Source: Internet
Author: User

Zookeeper

Visual C #, as the next-generation mainstream programming language, is well known for its powerful language functions. And there is a very rich content of the Program Development Kit-. Net FrameWork SDK, as his backing. In this way, Visual C # has a stage to give full play to its skills. The powerful functions of Visual C # not only support data processing of various databases, but also network programming and file processing.

The recycle bin of a Windows operating system is a protection measure for files. Its main function is self-evident. In the new Windows 2000 system, when I delete a file to the recycle bin, I press the "Clear recycle bin" button to clear the recycle bin. The prompt "the folder is not empty, "information cannot be deleted. Therefore, you have to recover all the files and then delete the files in the folder to be deleted. Then, you can clear the recycle bin. But this has brought us troubles in the operating system. This article is to use Visual C #'s powerful functions in file processing to make a software, using this software to clear the files to be deleted in the recycle bin, so as to relieve such troubles.

I. Main Idea of Program Design

We know that the windows system temporarily stores all the file information we want to delete in the "C: \ Recycled" directory. Use the "Clear recycle bin" button to complete the files to be deleted in this directory. The main idea of this program is based on the above knowledge. The details are as follows:

(1) first, judge whether the "Recycled" directory under the C root directory is empty.

(2). If it is not null, it traverses all file information and deletes the file.

Ii. Programming and running environment

(1) Windows 2000 Professional Edition

(2). Net FrameWork SDK Beta 2

Iii. Main steps and explanations of Program Design

(1) Determine whether the "Recycled" directory under the C root directory is empty.

To determine whether file information exists in the "C: \ Recycled" directory, follow two steps to first locate the directory. Second, you can determine whether the directory is empty. The following describes the two steps:

I>. How to find the "C: \ Recycled" directory in the program.

The. Net FrameWork SDK encapsulates a namespace-System. IO. This namespace defines many classes, objects, attributes, and methods related to file and directory processing. Visual C # allows you to flexibly call these resources to perform operations on files and directories. This article mainly uses two types of namespace: Directory class and File class. The former is mainly used in programs to process directory-related operations, such as determining directories and obtaining file information in directories. The latter is mainly used in programs to process file-related operations, such as deleting files. The GetFiles ("Directory name") method in the Directory class is used in the program. This method returns an enumeration type, which is composed of a group of strings. The GetFiles () method forms a string for each file name in the directory, and then consists of these strings to form an enumeration type.

Ii>. Check whether the directory is empty.

This section describes the foreach statement. Visual C # uses this statement to collect enumeration data. In this article, we will use it to list all the information about the deleted files that exist in "C: \ Recycled.

Int c = 0; // defines this variable to determine whether the file foreach (string s1 in Directory) exists in the Directory. getFiles ("c :\\ recycled") // returns the enumerated type {++ c ;}if (c> 0) of the string row of the file name) // determine whether a file exists. If c> 0, there is a file in the recycle bin. Otherwise, there is no {.....}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.