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

Help comparing and killing.

P: 3
Hi I am having a little bit of trouble looking for a file in a directory that has random letters & numbers after "D20" how would i use the Dir command to check if this file exists while using the InStr function to get the file name of the file starting with "D20" and then killing it.

Much help is appreciated thanks.
Mar 16 '07 #1
Share this Question
Share on Google+
5 Replies


P: 3
Visual Basic 6.0 anyone go any suggestions please?
Mar 17 '07 #2

vijaydiwakar
100+
P: 579
Hi I am having a little bit of trouble looking for a file in a directory that has random letters & numbers after "D20" how would i use the Dir command to check if this file exists while using the InStr function to get the file name of the file starting with "D20" and then killing it.

Much help is appreciated thanks.
dear i want more detail.
and sho me ur code so far
Mar 17 '07 #3

P: 3
Another program creates a few cache files wich i want to delete there are certain characters that are always the same in the name at the start "D20" and then the rest of the characters are random. I want to check if this file exists by using the dir function and then if it does exist delete it.

'retval1 = Dir$(App.Path & "\D20*.dat")
'If retval = "\D20*.dat" Then
'Kill (TxtDirectory.Text & "\D20*.dat")
'End If

This does not work as * or ? doesn't represent flaged characters. How would i go about doing this correctly. Thanks
Mar 17 '07 #4

vijaydiwakar
100+
P: 579
Another program creates a few cache files wich i want to delete there are certain characters that are always the same in the name at the start "D20" and then the rest of the characters are random. I want to check if this file exists by using the dir function and then if it does exist delete it.

'retval1 = Dir$(App.Path & "\D20*.dat")
'If retval = "\D20*.dat" Then
'Kill (TxtDirectory.Text & "\D20*.dat")
'End If

This does not work as * or ? doesn't represent flaged characters. How would i go about doing this correctly. Thanks
first collect all the file names in a array then apply left$(myarr(i),3)="D20" then kill it
Mar 17 '07 #5

Expert 5K+
P: 8,434
...
'retval1 = Dir$(App.Path & "\D20*.dat")
'If retval = "\D20*.dat" Then
'Kill (TxtDirectory.Text & "\D20*.dat")
'End If
Actually, this code looks fine apart from a couple of things.
  • It's commented out. :D
  • You're checking the wrong variable (retval instead of retval1).
  • Retval will contain just the file name, no wildcard characters and no "\" at the front.
  • Why two different paths? (App.Path -vs- TxtDirectory.Text)
You might try something like this...
Expand|Select|Wrap|Line Numbers
  1. retval = Dir$(App.Path & "\D20*.dat")
  2. If retval <> "" Then
  3.   Kill (App.Path & "\" & retval)
  4. End If
Mar 19 '07 #6

Post your reply

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