⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 自动建立文件夹.frm

📁 可以自动建立删除文件夹, 提供了多种方法以供参考
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3855
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3855
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text1 
      Height          =   855
      Left            =   0
      TabIndex        =   7
      Text            =   "C:\Documents and Settings\Administrator\桌面\test"
      Top             =   3000
      Width           =   4455
   End
   Begin VB.CommandButton Command3 
      Caption         =   "建立文件夹,并在文件夹写入文件,并删除该文件"
      Height          =   1215
      Left            =   1440
      TabIndex        =   6
      Top             =   120
      Width           =   1455
   End
   Begin VB.CommandButton Command6 
      Caption         =   "删除文件夹内所有内容,并删除文件夹3"
      Height          =   615
      Left            =   3120
      TabIndex        =   5
      Top             =   1560
      Width           =   1335
   End
   Begin VB.CommandButton Command5 
      Caption         =   "判断文件夹内文件个数2"
      Height          =   615
      Left            =   3120
      TabIndex        =   3
      Top             =   840
      Width           =   1335
   End
   Begin VB.CommandButton Command4 
      Caption         =   "判断有无重名文件夹,并建立新文件夹1"
      Height          =   615
      Left            =   3120
      TabIndex        =   2
      Top             =   120
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "建立文件夹"
      Height          =   855
      Left            =   120
      TabIndex        =   1
      Top             =   0
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "删除文件夹"
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   1080
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   780
      Left            =   120
      TabIndex        =   4
      Top             =   2160
      Width           =   4380
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click()
    If Dir(Text1.Text, vbDirectory) <> "" Then
      MsgBox "文件夹:" & Text1.Text & "存在!"
   Else
      MkDir Text1.Text
      MsgBox "创建文件夹" & "shishi成功"
End If

End Sub

Private Sub Command2_Click()
If Dir(Text1.Text & "\") <> "" Then
  Ti = MsgBox("文件夹里有文件,是否删除?", vbOKCancel)
      If Ti = 1 Then
               Kill (Text1.Text & "\*")
               MsgBox "要删除文件夹,请再按一下按钮"
               Command2.Caption = "要删除文件夹,请再按一下我"
       Else
              End
      End If
Else
   Ti = MsgBox("你确定要删除文件夹吗?", vbOKCancel)
       If Ti = 1 Then RmDir Text1.Text
 End If
End Sub


Private Sub Command3_Click()
'[VBScript]
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(Text1.Text & "\testfile.txt", True)
MyFile.WriteLine ("This is a test.")
MsgBox "文件已经写入"
MyFile.Close
Set MyFile = fso.GetFile(Text1.Text & "\testfile.txt")
Ti = MsgBox("是否要删除文件", vbOKCancel)
 If Ti = 1 Then
             MyFile.Delete
  Else
            End
 End If
End Sub

'==================================================================================================
'1、判断有无同名文件夹,并建立新文件夹
Public FolderCount As Integer '以便于最终删除文件夹command6
Private Sub Command4_Click()
         Dim fso As New FileSystemObject
If fso.FolderExists(Text1.Text) Then
    MsgBox "要创建的文件已存在!", vbOKOnly, "警告"
Else
    fso.CreateFolder (Text1.Text)
    Label1.Caption = Text1.Text + "创建成功!"
End If
End Sub
 
'至此,新建文件夹功能已经实现!
 
'2、下边我们来实现判断文件夹是否为空!
 
Private Sub Command5_Click()
       Dim fso As New FileSystemObject
If Not fso.FolderExists(Text1.Text) Then
        MsgBox "要判断的文件不存在!", vbOKOnly, "警告"
    ElseIf Dir(Text1.Text & "\") <> "" Then
            Ti = MsgBox("文件夹里有文件,是否删除?", vbOKCancel)
    
        Dim FolderSize As Long
        FolderCount = fso.GetFolder(Text1.Text & "\").SubFolders.Count
        Debug.Print FolderCount
        Label1.Caption = Str(FolderCount)
        
        If FolderCount Then
            MsgBox "此文件夹共有:" + Str(FolderCount) + "个文件\文件夹!", vbOKOnly, "警告"
        Else
            MsgBox "此文件夹为空!", vbOKOnly, "警告"
        End If
    End If
End Sub
'3、删除文件夹内容及文件夹
Private Sub Command6_Click()
    Dim fso As New FileSystemObject 'Scripting.FileSystemObject
     Pathh = Text1.Text
Tip = MsgBox("是否将文件夹所有内容清空", vbOKCancel)
      If Tip = 1 Then
         If Dir(Text1.Text & "\") <> "" Then Kill (Text1.Text & "\*.*")
             Tip = MsgBox("是否将文件夹删除", vbOKCancel)
               If Tip = 1 Then
                    'If fso.FolderExists(Text1.Text) Then MsgBox "删除成功":
                    Pathh.Delete 'fso.DeleteFolder (Text1.Text)    '==RmDir Text1.Text '
               Else
                    End
               End If
      Else
        End
      End If
       

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -