Test for file to KILL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mal  Reeve

    #1

    Test for file to KILL

    Hi,

    I am using the KILL command to either empty a directory, or delete a file.

    How do I test for the files existence first, since attempting to delete a
    non-existent file causes an error.

    I tried the LEN command but this also errors if there is no file.

    ideas??

    Mal.


  • PC Datasheet

    #2
    Re: Test for file to KILL

    Mal,

    Look at the Dir method.


    --
    PC Datasheet
    Your Resource For Help With Access, Excel And Word Applications
    resource@pcdata sheet.com



    "Mal Reeve" <lorimal@earthl ink.net> wrote in message
    news:NIFLc.8853 $f4.7387@newsre ad3.news.atl.ea rthlink.net...[color=blue]
    > Hi,
    >
    > I am using the KILL command to either empty a directory, or delete a file.
    >
    > How do I test for the files existence first, since attempting to delete a
    > non-existent file causes an error.
    >
    > I tried the LEN command but this also errors if there is no file.
    >
    > ideas??
    >
    > Mal.
    >
    >[/color]


    Comment

    • Allen Browne

      #3
      Re: Test for file to KILL

      Use the Len() of the Dir$(), and include the $.

      --
      Allen Browne - Microsoft MVP. Perth, Western Australia.
      Tips for Access users - http://allenbrowne.com/tips.html
      Reply to group, rather than allenbrowne at mvps dot org.

      "Mal Reeve" <lorimal@earthl ink.net> wrote in message
      news:NIFLc.8853 $f4.7387@newsre ad3.news.atl.ea rthlink.net...[color=blue]
      >
      > I am using the KILL command to either empty a directory, or delete a file.
      >
      > How do I test for the files existence first, since attempting to delete a
      > non-existent file causes an error.
      >
      > I tried the LEN command but this also errors if there is no file.[/color]


      Comment

      • Trevor Best

        #4
        Re: Test for file to KILL

        Allen Browne wrote:[color=blue]
        > Use the Len() of the Dir$(), and include the $.
        >[/color]
        Is that Aussie dollars Allen? Or US? :-)

        --
        Error reading sig - A)bort R)etry I)nfluence with large hammer

        Comment

        • Allen Browne

          #5
          Re: Test for file to KILL

          "Trevor Best" <nospam@localho st> wrote in message
          news:40ff6856$0 $26088$afc38c87 @auth.uk.news.e asynet.net...>[color=blue][color=green]
          > > Use the Len() of the Dir$(), and include the $.
          > >[/color]
          > Is that Aussie dollars Allen? Or US? :-)[/color]

          Groan!

          People have been Pounded for less.

          :-)


          Comment

          • Keith Wilby

            #6
            Re: Test for file to KILL

            "Allen Browne" <AllenBrowne@Se eSig.Invalid> wrote:
            [color=blue]
            > People have been Pounded for less.[/color]

            for Cent-uries ;-)

            Comment

            • Nick Coe \(UK\)

              #7
              Re: Test for file to KILL

              Why not trap the error number and ignore it?

              Function ZapFile(strFNam e As String) As Boolean
              On Error GoTo HandleErr

              Kill strFName

              ZapFile = True

              ExitHere:
              Exit Function

              HandleErr:
              Select Case Err.Number
              Case 53
              'File does not exist could not Kill
              Resume Next
              Case Else
              MsgBox "Error " & Err.Number & ": " & Err.Description ,
              vbCritical, "nccHProgs.ZapF ile"
              End Select

              Resume ExitHere

              End Function


              --
              Nick Coe (UK)


              ---

              "Mal Reeve" <lorimal@earthl ink.net> wrote in message
              news:NIFLc.8853 $f4.7387@newsre ad3.news.atl.ea rthlink.net...[color=blue]
              > Hi,
              >
              > I am using the KILL command to either empty a directory,[/color]
              or delete a file.[color=blue]
              >
              > How do I test for the files existence first, since[/color]
              attempting to delete a[color=blue]
              > non-existent file causes an error.
              >
              > I tried the LEN command but this also errors if there is[/color]
              no file.[color=blue]
              >
              > ideas??
              >
              > Mal.
              >
              >[/color]


              Comment

              • david epsom dot com dot au

                #8
                Re: Test for file to KILL

                ??? dir returns a string, not a variant.

                (david)

                "Allen Browne" <AllenBrowne@Se eSig.Invalid> wrote in message
                news:40ff2c47$0 $29286$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
                > Use the Len() of the Dir$(), and include the $.
                >
                > --
                > Allen Browne - Microsoft MVP. Perth, Western Australia.
                > Tips for Access users - http://allenbrowne.com/tips.html
                > Reply to group, rather than allenbrowne at mvps dot org.
                >
                > "Mal Reeve" <lorimal@earthl ink.net> wrote in message
                > news:NIFLc.8853 $f4.7387@newsre ad3.news.atl.ea rthlink.net...[color=green]
                > >
                > > I am using the KILL command to either empty a directory, or delete a[/color][/color]
                file.[color=blue][color=green]
                > >
                > > How do I test for the files existence first, since attempting to delete[/color][/color]
                a[color=blue][color=green]
                > > non-existent file causes an error.
                > >
                > > I tried the LEN command but this also errors if there is no file.[/color]
                >
                >[/color]


                Comment

                Working...