By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

compare files

P: 7
Hi,
can any one told me how to compare files with same name but different extension..
for eg.
if a.txt & a.doc then ans is same files..
Thanks
Aug 27 '07 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
Hi,
can any one told me how to compare files with same name but different extension..
for eg.
if a.txt & a.doc then ans is same files..
Thanks
You'll have to explain what you mean by "same files". Obviously if they have different extensions then they are not the same file. If you mean the same contents then you need to read one line at a time from each file and compare them for equality (that's if both contain text only).
Aug 27 '07 #2

dip_developer
Expert 100+
P: 648
Hi,
can any one told me how to compare files with same name but different extension..
for eg.
if a.txt & a.doc then ans is same files..
Thanks
if you just want to compare the file names (without extension) then use the split() method to take out the name and compare them. try this code.....(i am taking two file names in two text boxes)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim firstFileName As String = TextBox2.Text.Split(".")(0) 
  3. Dim secondFileName As String = TextBox3.Text.Split(".")(0)
  4.  
  5. If String.Compare(firstFileName, secondFileName) = 0 Then
  6. MsgBox("Both file names are same")
  7. Else
  8. MsgBox("File names are different")
  9. End If
  10.  
is this the answer you are looking for????....may be I have not understood your question......reply us
Aug 27 '07 #3

10K+
P: 13,264
if you just want to compare the file names (without extension) then use the split() method to take out the name and compare them. try this code.....(i am taking two file names in two text boxes)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim firstFileName As String = TextBox2.Text.Split(".")(0) 
  3. Dim secondFileName As String = TextBox3.Text.Split(".")(0)
  4.  
  5. If String.Compare(firstFileName, secondFileName) = 0 Then
  6. MsgBox("Both file names are same")
  7. Else
  8. MsgBox("File names are different")
  9. End If
  10.  
is this the answer you are looking for????....may be I have not understood your question......reply us
Yep, I've just looked at their example again and I think that's what they want.
Aug 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.