Help comparing and killing.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Binaries
    New Member
    • Mar 2007
    • 3

    Help comparing and killing.

    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.
  • Binaries
    New Member
    • Mar 2007
    • 3

    #2
    Visual Basic 6.0 anyone go any suggestions please?

    Comment

    • vijaydiwakar
      Contributor
      • Feb 2007
      • 579

      #3
      Originally posted by Binaries
      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

      Comment

      • Binaries
        New Member
        • Mar 2007
        • 3

        #4
        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.T ext & "\D20*.dat" )
        'End If

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

        Comment

        • vijaydiwakar
          Contributor
          • Feb 2007
          • 579

          #5
          Originally posted by Binaries
          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.T ext & "\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

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by Binaries
            ...
            'retval1 = Dir$(App.Path & "\D20*.dat" )
            'If retval = "\D20*.dat" Then
            'Kill (TxtDirectory.T ext & "\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.Te xt)
            You might try something like this...
            Code:
            retval = Dir$(App.Path & "\D20*.dat")
            If retval <> "" Then
              Kill (App.Path & "\" & retval)
            End If

            Comment

            Working...