找不到杀死路径文件

Kill path file not found

我正在尝试删除以下文件夹中的所有文件。但是出现错误

run time error 75: path/file not found

但是有几点需要注意:

  1. 它确实删除了一些文件,但它永远不会删除相同的文件
  2. 路径确实存在

代码:

Sub deleteprevfixing()
    'First delete file contents
    Dim aFile As String
    aFile = "R:\samsfiles\sam\!test\*.*"

    If Len(Dir$(aFile)) > 0 Then
         Kill aFile
    End If
End Sub

如果你想删除文件夹中的所有文件(正如你的问题所暗示的那样),你需要不断循环并调用dir()。否则,您只会删除 dir().

返回的第一个文件
Option Explicit

Sub DeleteAllFilesInFolder()

    Dim folderPath As String
    folderPath = "R:\samsfiles\sam\!test\"

    Dim Filename As String
    Filename = VBA.FileSystem.Dir$(folderPath & "*.*", vbNormal) ' The "*.*" here isn't really necessary, but I'll leave it as is.

    Do Until Len(Filename) = 0
        Kill folderPath & Filename
        Filename = VBA.FileSystem.Dir$()
    Loop

End Sub

全部排序 - 谢谢大家。这是因为从网络共享或映射驱动器中删除时我必须关闭 "Are you sure you want to permanently delete this file?" 对话框。

这是一个解决方法(从下面的源代码复制)

  1. 将网络驱动器映射到您要使用的网络共享。确保 驱动器在登录时重新连接。
  2. 浏览至 C:\users\<username>
  3. 右键单击此位置的其中一个文件夹(任何 文件夹,例如 "links"),然后单击属性。
  4. Select 位置选项卡。
  5. 单击“移动”,浏览到您在第 1 步中映射的驱动器的根目录, 然后单击 Select 文件夹。
  6. 单击“确定”,然后在对话框中单击“是” 出现了。

Please see attached for original thread