[RESOLVED] How to Check if file Name already Exist in a specified folder in my computer
Hi All,
I made a program to capture photo,make a file name to it base on the serial number of the items and save in a specified or selected path in my computer, I want to upgrade my program, so that when Users capture same items with same serial number it will alert and tell Users that this serial number is already captured,means already have copy in the path in my computer. so that user will not continue.
here is my code please help me modify it to avoid duplicate data in my specified path.
thanks in advanced.
Code:
'select path where to save the photo using folderbrowsedialog1
Private Sub btnSelectPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectPath.Click
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
txtPath.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
'when i click this button it will save the photo in a specified path with a fileName of serial number.
Private Sub btnTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTop.Click
Dim strFileName As String
strFileName = txtSerialNo.Text & Format(Now, " -T") & ".jpg"
If txtSerialNo.Text <> "" Then
PictureBox1.Image.Save(txtPath.Text & "\" & strFileName, System.Drawing.Imaging.ImageFormat.Jpeg)
Else
MsgBox("Scan Sn", MsgBoxStyle.Critical, "Error")
txtSerialNo.Focus()
End If
how can i check if the file name is already in the path i specified,
thank you.
Re: How to Check if file Name already Exist in a specified folder in my computer
To find information about files/folders, you can use the System.IO namespace, eg:
Code:
If System.IO.File.Exists(txtPath.Text & "\" & strFileName) Then
'it exists
End If
Re: How to Check if file Name already Exist in a specified folder in my computer
Re: How to Check if file Name already Exist in a specified folder in my computer
here a few samples...
Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim di As New IO.DirectoryInfo("E:\FebBackup\Berit Praxis")
' LINQ-Abfragestring
''//get .jpg Files not older than 3 monthes
'ListBox1.DataSource = (From fi As IO.FileInfo In di.GetFiles() _
' Where fi.Extension Like ".jpg" And fi.CreationTime > Now.AddMonths(-3) _
' Order By fi.LastAccessTime).ToList
''// get all jpg from Foldername
' ListBox1.DataSource = (From fi As IO.FileInfo In di.GetFiles() _
'Where fi.Extension Like ".JPG" _
'Order By fi.LastAccessTime).ToList
''// check if .jpg File is in Folder and return to Listbox
ListBox1.DataSource = (From fi As IO.FileInfo In di.GetFiles() _
Where fi.Name Like "Test.JPG" _
Order By fi.LastAccessTime).ToList
ListBox1.DisplayMember = "Name"
End Sub
regards
Chris
Re: How to Check if file Name already Exist in a specified folder in my computer
hi Sir si_the_geek ,
You made it very simple!!!!!
thank you very much!!
Re: How to Check if file Name already Exist in a specified folder in my computer
Quote:
Originally Posted by
BONITO
hi Sir si_the_geek ,
You made it very simple!!!!!
thank you very much!!
Code:
If System.IO.File.Exists(IO.Path.Combine(txtPath.Text, strFileName)) Then