Ok i want to check if a file exists in the Application.StartupPath. I tried My.Computer.FileSystem.FileExists but that checks the whole computer doesn't it. ? How do i check if a file exists in a directory?
Printable View
Ok i want to check if a file exists in the Application.StartupPath. I tried My.Computer.FileSystem.FileExists but that checks the whole computer doesn't it. ? How do i check if a file exists in a directory?
Not to the best of my knowledge, and MSDN implies that you need to specify the full path. As far as I can tell FielExists is exactly what you want - you just pass in the application startuppath as part of the argument.Quote:
My.Computer.FileSystem.FileExists but that checks the whole computer doesn't it
well it finds it if u just type in the filename.
Just use the System.IO.File.Exists function.
Hmm maybe I'm looking at a different namespace. There seem to be several FileExists methods scattered around the .Net framework!
This works fine for me :
I just picked a random file from my filesystem and tried two calls - one with full path, one without.Code:Imports Microsoft.VisualBasic.FileIO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Boolean = FileSystem.FileExists("WisCrPcs.exe")
Dim y As Boolean = FileSystem.FileExists("C:\Elements\patch\Clean\WisCrPcs.exe")
End Sub
End Class
The full path version works (y=true), the filename only doesn't (x=false)
For a specific file in a specific directroy, I use the System.IO.DirectoryInfo ... class ( the constructor takes a directory path), then use the FileExists function of the DI instance to find the file.
-tg