读书人

怎么判断另一台电脑上是否存在某个文件

发布时间: 2013-09-05 16:02:07 作者: rapoo

如何判断另一台电脑上是否存在某个文件路径
比如另一台电脑B和我是同一个局域网里面的,有个路径,路径为“C:\windows\Example”,我应该如何判断该路径是否在B电脑中存在呢?
[解决办法]
Directory.Exists(@"C:\windows\Example");
[解决办法]
直接判断貌似没这可能,看看c的


If IO.File.Exists(SKYTemplateFile) = False Then
‘文件不存在
If SKYTemplatePath.IndexOf("\\") = 0 Then
If Connect(SKYTemplatePath, lpRemoteUsr, lpRemotePass) = False Then
ShowMsgBox("...")
Return False
ElseIf IO.File.Exists(SKYTemplateFile) = False then
ShowMsgBox("...")
Return False
End If
Else
ShowMsgBox("...")
Return False


End If
End If

Public Function Connect(ByVal lpRemoteName As String, ByVal lpRemoteUsr As String, ByVal lpRemotePass As String) As Boolean
Dim intRtn As Integer

Try

Dim typNetResource As NETRESOURCE

With typNetResource
.dwScope = RESOURCE_CONNECTED
.dwType = RESOURCETYPE_DISK
.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
.dwUsage = RESOURCEUSAGE_CONTAINER
''.lpLocalName = LocalName
.lpRemoteName = lpRemoteName
End With

intRtn = WNetAddConnection2(typNetResource, lpRemotePass, lpRemoteUsr, CONNECT_UPDATE_PROFILE)
Select Case intRtn
Case 0
'连接
Case Else
'连接Error
Return False

End Select

Return True



Catch ex As Exception
Throw ex
Return False
Finally
End Try

End Function


[解决办法]
引用:
Directory.Exists(@"C:\windows\Example");
+1
[解决办法]
引用:
Quote: 引用:

Directory.Exists(@"C:\windows\Example");
+1

这只能是本机的吧
[解决办法]
引用:
Directory.Exists(@"C:\windows\Example");

这句只适合本地文件是否存在
楼主可以试试
(!Directory.Exists("\\对方ip\要找的文件夹"));
但是要找的文件夹必须是共享的你能访问到,
[解决办法]
引用:
Quote: 引用:

Quote: 引用:

Directory.Exists(@"C:\windows\Example");
+1

这只能是本机的吧

我去 好吧 我表示我看错问题了。话说能实现吗 你如果能随意看到对方的文件不就是黑了他的电脑了吗。。
[解决办法]
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

Directory.Exists(@"C:\windows\Example");
+1

这只能是本机的吧

我去 好吧 我表示我看错问题了。话说能实现吗 你如果能随意看到对方的文件不就是黑了他的电脑了吗。。

我表示,一开始也看错了。
有两种概念:
第一是,对方电脑必须要有可利用的漏洞。
第二是,对方电脑必须提供一种接口。
有以上两种的其中一种,就可以实现你的功能了。
但第一种有点扯淡。
我详细说说第二种,利用第二种提供接口,让对方电脑给你返回信息。可以是文件夹共享、FTP、WEB SERVICE、套接字、windows消息队列等

读书人网 >C#

热点推荐