且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查服务器上的文件是否存在(update.date.txt)

更新时间:2023-11-27 19:07:22

使用使用以下方法之一在目录中搜索文件:

http://msdn.microsoft.com/en-us/library/wz42302f%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ms143316%28v= vs.110%29.aspx [ ^ ]。



一切都取决于你如何选择文件掩码(第二个参数, searchPattern )。要获取所有文件,请使用update。* .txt或* .txt或update。*。或按年份选择:* .2014.txt。等等...



获取一系列文件名,然后按照你描述的方式对它们进行分析。



正如我所说,你有一个问题:糟糕的目录选择。一般来说,它是只读的。请看我过去的答案:

http://www.codeproject.com/Questions/454593/How-to-find-my-programs-directory

如何查找我的程序目录可执行目录),

如何查找我的程序目录当前目录,特殊文件夹 )。



此外,请注意这个小问题,以防万一:

Directory.Get.Files搜索模式问题 [ ^ ]。



-SA


它不是太复杂。看看这里: http://***.com / questions / 1979915 / can-i-check-if-a-file-exists-at-a-url [ ^ ] - 它建议使用HttpWebRequest,它可以正常工作。



如果要列出Web资源中的文件并检查最新版本,请参阅此处:http://***.com/questions/124492/c-sharp-httpwebrequest-command-to-get-directory-listing [ ^ ]

Im making an updating system for a game launcher and that's why i'm trying to check if this file exists:
Update.[datestring].txt
the datestring wil be different every update so that the updater can check this with the local file if the two do not mach
(so if there is a newer version) the launcher will download the new update

how can i check this

Code so far:

If My.Computer.FileSystem.FileExists(Application.StartupPath & "update/Update.[datestring].txt") Then
    MsgBox("File found.")
Else
    MsgBox("File not found.")
End If



please help me

Regards

Bart de Lange

Use the file search in the directory using one of these methods:
http://msdn.microsoft.com/en-us/library/wz42302f%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspx[^].

Everything depends on how you chose the file mask (second parameter, searchPattern). To take all files, use "update.*.txt" or just "*.txt" or "update.*". Or select by year: "*.2014.txt". And so on…

Obtain an array of file names and then analyze them the way you described.

As I say, you have one problem: bad choice of directory. Generally speaking, it is read-only. Please see my past answers:
http://www.codeproject.com/Questions/454593/How-to-find-my-programs-directory
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

Also, be aware of this minor problem, just in case:
Directory.Get.Files search pattern problem[^].

—SA


It's not too complex. Have a look here: http://***.com/questions/1979915/can-i-check-if-a-file-exists-at-a-url[^] - it suggests using an HttpWebRequest, which will work fine.

If you want to list the files in the web resource and check for the latest version, then see here: http://***.com/questions/124492/c-sharp-httpwebrequest-command-to-get-directory-listing[^]