2016-04-19, 12:31 AM
|
#1
|
版區管理員
|
[使用版本VB2008]檔案直接刪除的程式[檔案剪碎工具]
顧名思義就是直接刪除檔案而不丟入回收桶(有人建議命名為碎紙機)
當將要刪除的檔案拖曳到程式圖示上時,程式就會顯示是否永久刪除這些檔案
如果直接執行程式,會出現建立捷徑及清空回收桶的功能
有試過用C++ Builder寫,可惜的是C++ Builder無法處理UTF-8格式的檔名
以下是程式碼:
引用:
作者: Form1.vb
Public Class Form1
PHP 語法:
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Int32, ByVal pszRootPath As String, ByVal dwFlags As Int32) As Int32
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Int32
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Application.CommandLineArgs.Count > 0 Then
Application.DoEvents()
If MsgBox("確定要永久刪除這 " & My.Application.CommandLineArgs.Count & " 個項目?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
For i = 0 To My.Application.CommandLineArgs.Count - 1
If My.Computer.FileSystem.FileExists(My.Application.CommandLineArgs(i).ToString) Then
My.Computer.FileSystem.DeleteFile(My.Application.CommandLineArgs(i).ToString, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
Else
My.Computer.FileSystem.DeleteDirectory(My.Application.CommandLineArgs(i).ToString, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
Next
End If
Close()
End If
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\檔案剪碎工具.LNK") Then Button2.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SHEmptyRecycleBin(Me.Handle, vbNullString, 0)
SHUpdateRecycleBinIcon()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFolder As String = My.Computer.FileSystem.CurrentDirectory, strEXE As String = "Shredder.exe"
Dim objWS As Object
objWS = CreateObject("WScript.Shell")
With objWS.CreateShortCut(objWS.SpecialFolders("Desktop") & "\檔案剪碎工具.LNK") '& Replace(strEXE, ".EXE", ".LNK", 1, , 1))
.TargetPath = objWS.ExpandEnvironmentStrings(strFolder & "\" & strEXE)
.WorkingDirectory = strFolder
.Description = "檔案剪碎工具"
.WindowStyle = 4
.IconLocation = objWS.ExpandEnvironmentStrings(strFolder & "\" & strEXE & ",0")
.Save()
End With
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Close()
End Sub
End Class
|
以下是表單:
引用:
作者: Form1.Designer.vb
PHP 語法:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form 覆寫 Dispose 以清除元件清單。
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'為 Windows Form 設計工具的必要項
Private components As System.ComponentModel.IContainer
'注意: 以下為 Windows Form 設計工具所需的程序
'可以使用 Windows Form 設計工具進行修改。
'請不要使用程式碼編輯器進行修改。
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(12, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "清空回收桶"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(12, 41)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "建立捷徑"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(12, 70)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(75, 23)
Me.Button3.TabIndex = 2
Me.Button3.Text = "關閉"
Me.Button3.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(100, 104)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Shredder"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
End Class
|
此帖於 2016-04-30 10:42 AM 被 mini 編輯.
|
__________________
『唸金母心咒:嗡。金母。悉地。吽。』
持此咒者,可免一切瘟疫,一切瘟神抱頭四散。
魔術就是欣賞神奇的效果
如果魔術的秘密被破解了
那魔術就失去欣賞的價值
|
|
送花文章: 1539,
收花文章: 1563 篇, 收花: 3911 次
|