To empty the Recycle Bin with Visual C #

Source: Internet
Author: User
Tags foreach

Visual C #, as the next-generation mainstream program development language, is known for its powerful language capabilities. And there is a very rich content of the program development package--. Net FrameWork SDK, as his backing. This makes Visual C # a stage to give full play to its capabilities. The powerful features of Visual C # are not only in supporting data processing of various databases, but also in the aspects of network programming and file processing.

Windows operating system of the Recycle Bin is a document protection measures, he mainly is the role is self-evident. In the new Windows 2000 system, when I delete the file to the Recycle Bin, press the "Empty Recycle Bin" button, want to empty the Recycle Bin, at this point, often prompted "So-and-so folder is not empty, can not delete" information. So have to restore all, and then to delete the folder, first delete the file inside, and then delete the folder, so you can empty the Recycle Bin. But this has brought trouble to our operating system. This article is to take advantage of Visual C # in the processing of files, a powerful function to do a software, using this software to empty the Recycle Bin inside the file to delete, thereby relieving this annoyance.

I. Main ideas of programming

We know that the Windows system will temporarily save the file information we are about to delete under the "C:\Recycled" directory. Complete the file to be deleted in this directory through the "Empty Recycle Bin" button. The main idea of this procedure is based on the above knowledge. The details are as follows:

(1). First, determine whether the "recycled" directory below the C-packing directory is empty.

(2). If not empty, traverse all file information and delete the file.

Two. Programming and operating environment

(1). Windows System 2000 Professional Edition

(2). Net FrameWork SDK Beta 2

Three. Main steps and specific explanations for programming

(1). How to determine whether the "recycled" directory below the C-packing directory is empty.

To determine if there are any file information in the "C:\Recycled" directory, go through two steps, first to find the directory. Second, we can determine if this directory is empty. Following these two steps to do a specific introduction:

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

A namespace--system.io is encapsulated in the. Net FrameWork SDK. Many of the classes, objects, properties, and methods associated with file and directory processing are defined in this namespace. Visual C # is the flexibility to invoke these resources to implement specific operations on files and directories. This article mainly uses two classes in this namespace: The Directory class and the file class. The former is primarily used in programs to handle directory-related operations, such as determining directories and obtaining file information in a directory. The latter is primarily used in programs to handle file-related operations, such as deleting files. In a program using the GetFiles ("Directory Name") method in the Directory class, this method returns an enumerated type that consists of a set of strings. The GetFiles () method forms a string of each file name in the directory, which is then composed of these strings to form an enumeration type.

Ii> Determine if this directory is empty.

Here is a description of the foreach statement, which is used by Visual C # to collect enumerations. In this article, it is through him to enumerate all the deleted file information that exists in "C:\Recycled".

int c = 0 ; // 定义此变量主要是来判断目录中是否有文件
foreach ( string s1 in Directory.GetFiles ( "c:\\recycled" ) ) // 返回文件名称字符串行时的枚举类型
{
 ++c ;
}
if ( c > 0 ) //判断是否存在文件如果 c > 0则回收站有文件,反之则没有
{
 …..
}

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.