以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  移动文件报错  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=186603)

--  作者:lds
--  发布时间:2023/5/15 11:48:00
--  移动文件报错
For Each File As String In FileSys.GetFiles("D:\\")
If File <> "D:\\pagefile.sys" Then
If File <> "D:\\DumpStack.log.tmp" Then
If File <> "D:\\{e617-37ba-87c4-4622-add1-3fe8-1d1a-2b52}" Then
Dim s As String = FileSys.GetName(file)
s = s.replace("~$", "")

ShowAppWindow(s, 5)

If FileSys.FileExists("d:\\" & s) Then
FileSys.MoveFile("d:\\" & s, "d:\\123\\" & s, True)
End If
End If
End If
End If
 希望将D盘根目录的文件移动到 d:\\123 文件夹, 但D盘有隐藏文件,排除隐藏文件后,能正常移动,但文件打开后移动报错, 该如何跳过隐藏文件并关闭文件后移动?
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2023/5/15 12:02:00
--  
判断打开:http://www.foxtable.com/webhelp/topics/2126.htm

ShowAppWindow只能用来关闭指定标题的窗口,不是关闭文件或者应用程序的。

试试kill
Dim ps As  System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("某进程名称")
For Each p As System.Diagnostics.Process In ps
    msgbox(p.MainWindowTitle)
    p.kill
Next

个人的建议是提醒用户有打开的文件,让用户自己关闭文件,再重新移动

--  作者:lds
--  发布时间:2023/5/15 12:03:00
--  
收到,谢谢