返回列表 上一主題 發帖

[發問] 指定資料夾指定條件刪除檔案問題請教

[發問] 指定資料夾指定條件刪除檔案問題請教

DEAR  ALL 大大
1.需求整頓資料庫內之年代久遠無用之檔案刪除
1.1 原則如下
A. 資料夾路徑 :  \\pcbfs02\C701\
B.檔案修改日期 <= 2010/01/01 前之 ALL 檔案刪除
2.請問自動化程式如何書寫 煩不吝賜教  THANKS*10000

回復 1# rouber590324
試試看
引用項目 Microsoft Scripting Runtime
Sub file_Delete()
Dim myFso As Scripting.FileSystemObject
Dim myFiles As Scripting.Files
Dim myFile As Scripting.File
Set myFso = New Scripting.FileSystemObject
Path = "\\pcbfs02\C701\"   '路徑請自行修正
Set myFiles = myFso.GetFolder(Path).Files
For Each myFile In myFiles
   If myFile.DateLastModified < "2010/1/1" Then myFile.Delete  '以檔案最後更新日判斷
Next
End Sub

TOP

DEAR  大大
停於     myFso As Scripting.FileSystemObject
秀出    使用者自訂型態尚未設定
煩不吝賜教    THANKS*10000

TOP

Dim myFiles As Object, xFile As Object
xPath = "\\pcbfs02\C701\"
Set myFiles = CreateObject("Scripting.FileSystemObject").GetFolder(xPath).Files
For Each xFile In myFiles
   If xFile.DateLastModified < CDate("2010/1/1") Then xFile.Delete
Next

TOP

回復 3# rouber590324

引用項目請增加 Microsoft Scripting Runtime

TOP

DEAR  准大 /  jcchiang 大大
  OK   THANKS*10000

TOP

        靜思自在 : 人的眼睛長在前面,只看到別人的缺點,絲毫看不到自己的缺點。
返回列表 上一主題