|
-
Jun 26th, 2018, 04:30 AM
#1
Thread Starter
Lively Member
[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.
-
Jun 26th, 2018, 05:05 AM
#2
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
-
Jun 26th, 2018, 05:06 AM
#3
Re: How to Check if file Name already Exist in a specified folder in my computer
Please remember next time...elections matter!
-
Jun 26th, 2018, 05:13 AM
#4
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
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Jun 26th, 2018, 06:05 AM
#5
Thread Starter
Lively Member
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!!
-
Jun 26th, 2018, 02:58 PM
#6
Re: How to Check if file Name already Exist in a specified folder in my computer
 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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|