在VB中检查桌面上的文件

发布于 2024-12-11 04:40:27 字数 418 浏览 3 评论 0原文

有没有办法在VB中搜索桌面上的文件(快捷方式文件)? 我试过: 如果 My.Computer.FileSystem.FileExists("桌面\MYFILE.lnk") 不返回任何内容

If My.Computer.FileSystem.FileExists("Desktop\MYFILE.exe") 不返回任何内容

If My.Computer.FileSystem.FileExists(Environment.SpecialFolder.Desktop\MYFILE.lnk") 不返回任何内容

If My.Computer.FileSystem.FileExists(Environment.SpecialFolder.Desktop\MYFILE.exe") 不返回任何内容

我也在谷歌上搜索过这个似乎找不到任何东西。

谢谢。

Is there anyway of searching for a file (shortcut file) on the desktop in VB?
I've tried :
If My.Computer.FileSystem.FileExists("Desktop\MYFILE.lnk")
doesnt return anything

If My.Computer.FileSystem.FileExists("Desktop\MYFILE.exe")
doesnt return anything

If My.Computer.FileSystem.FileExists(Environment.SpecialFolder.Desktop\MYFILE.lnk")
doesnt return anything

If My.Computer.FileSystem.FileExists(Environment.SpecialFolder.Desktop\MYFILE.exe")
doesnt return anything

I have searched for this too on google can't seem to find anything.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

柠栀 2024-12-18 04:40:27
System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\MYFILE.exe")
System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\MYFILE.exe")
遗弃M 2024-12-18 04:40:27
Public Function DesktopShortcutExists(ByVal sShortCutName As String) As Boolean
    Dim sPublicPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory) & "\" & sShortCutName & ".lnk"
    Dim sUserPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\" & sShortCutName & ".lnk"
    Return File.Exists(sPublicPath) = True Or File.Exists(sUserPath) = True
End Function
Public Function DesktopShortcutExists(ByVal sShortCutName As String) As Boolean
    Dim sPublicPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory) & "\" & sShortCutName & ".lnk"
    Dim sUserPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\" & sShortCutName & ".lnk"
    Return File.Exists(sPublicPath) = True Or File.Exists(sUserPath) = True
End Function
淡墨 2024-12-18 04:40:27

除非你的问题刚刚输入错误,请原谅我的 VB 技能,但它不应该是:

> If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\MYFILE.lnk")
> Then
>     ' Do Something
> End

C# 我会使用:

if(System.IO.File.Exists(string.format("{0}{1}", Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), @"\MYFILE.lnk")))
{
  // do something with file
}

Unless you question has just been type incorrectly, and forgive my VB skills, but should it not be:

> If My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\MYFILE.lnk")
> Then
>     ' Do Something
> End

C# I would use:

if(System.IO.File.Exists(string.format("{0}{1}", Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), @"\MYFILE.lnk")))
{
  // do something with file
}
So尛奶瓶 2024-12-18 04:40:27

您是否尝试过这样的操作:

If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myfile.lnk")

基本上我只是想知道您是否确保字符串连接正确,并在必要时使用 \ 。

Have you tried it like this:

If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\myfile.lnk")

Basically I just want to know if you are making sure that your string concatenation is correct, and using the \ when necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文