Results 1 to 8 of 8

Thread: Hiya every body

  1. #1

    Thread Starter
    Addicted Member Skeen's Avatar
    Join Date
    Jul 2000
    Location
    Abingdon, Oxon
    Posts
    138

    Thumbs up

    Can anyone tell me the correct syntax for this piece of code, I want to 'KILL' a file if it exists:

    If Command() + "nng_list.DOC" = True Then
    Kill Command() + "nng_list.DOC"
    End If

    At the moment, the compiler reads the first line, then passes straight to the 'End If', even if the file in question exists. [The Command() funtion holds the directory]

    Cheers 'n' Beers

    Skeen
    "It wasn't the booze that made me snooze, It was the Gin that did me in!"

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    May be you forgot you "\" between command() and nng_list.DOC

    Code:
    If Command() + "\nng_list.DOC" = True Then 
    Kill Command() + "\nng_list.DOC" 
    End If
    You can use dir("yourpath\yourfile.doc")
    It return "" if not exist else it return the path.

  3. #3

    Thread Starter
    Addicted Member Skeen's Avatar
    Join Date
    Jul 2000
    Location
    Abingdon, Oxon
    Posts
    138

    Thumbs down Still not workin'

    Thanx 4 the reply,

    It gives me a type mismatch error if I use:

    dir("yourpath\yourfile.doc")

    Cheers though
    "It wasn't the booze that made me snooze, It was the Gin that did me in!"

  4. #4
    Guest
    Here is a litle function to see if a file exist or not.
    Code:
    Public Function Existfile(ByVal sFile As String) As Boolean
       
      Dim sResults As String
    
      On Error GoTo Err_ExistFile
    
      sResults = Dir$(sFile)
      If sResults = Empty Then
        Existfile = False
      Else
        Existfile = True
      End If
      
      Exit Function
    
    Err_ExistFile:
      Existfile = False
    
    End Function
    And you can use it like this.
    Code:
    If Existfile("C:\nng_list.DOC") = True Then
      Kill "C:\nng_list.DOC"
    End If

  5. #5
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Sorry for the Dir,it's because it return a value
    isThere=dir("....")

  6. #6

    Thread Starter
    Addicted Member Skeen's Avatar
    Join Date
    Jul 2000
    Location
    Abingdon, Oxon
    Posts
    138

    Thumbs up Cheers Chaps

    Nice 1. I was trying the old 'Open-Close-KILL' gag. Wasn't up ta much either.

    Thax again

    Skeen
    "It wasn't the booze that made me snooze, It was the Gin that did me in!"

  7. #7
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Here's the function I prefer:

    Code:
    ' Check if file exists without disturbing Dir() function
    ' If file does not exist, but folder with same name does, return False
    ' If drive not ready, file exists and is corrupted, or network unavailable, return false
    Public Function FileExists(pstrFile As String) As Boolean
    On Error GoTo FileExistsErr
    
        FileExists = True
        If GetAttr(pstrFile) And vbDirectory Then FileExists = False
        
    FileExistsExit:
        Exit Function
        
    FileExistsErr:
        Select Case Err.Number
            Case 52, 53, 75
                FileExists = False
            Case Else
                MsgBox Err.Description, vbInformation, "Notice #" & Err.Number
        End Select
        Resume FileExistsExit
    End Function

  8. #8
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    And to delete a file, I use:

    Code:
    Public Function DeleteFile(pstrFile As String)
    On Error GoTo DeleteFileErr
        
        If InStr(pstrFile, "*") = 0 And InStr(pstrFile, "?") = 0 Then SetAttr pstrFile, vbNormal
        Kill pstrFile
    
    DeleteFileExit:
        Exit Function
        
    DeleteFileErr:
        MsgBox Err.Description, vbInformation, "Notice"
        Resume DeleteFileExit
    End Function
    Also, while I'm at it, these are good too:

    Code:
    Public Function FolderExists(pstrFolder As String) As Boolean
    On Error GoTo FolderExistsErr
    
        If GetAttr(pstrFolder) And vbDirectory Then FolderExists = True
        
    FolderExistsExit:
        Exit Function
        
    FolderExistsErr:
        If Err.Number = 53 Then
            FolderExists = False
        Else
            MsgBox Err.Description, vbInformation, "Notice"
        End If
        Resume FolderExistsExit
    End Function
    
    Public Function IsLocked(pstrFile As String) As Boolean
    On Error GoTo IsLockedErr
        IsLocked = False
        Open pstrFile For Binary As 1
        Close 1
        
    IsLockedExit:
        Exit Function
        
    IsLockedErr:
        Select Case Err.Number
            Case 70 ' Access Denied error
                IsLocked = True
            Case 75 ' Skip error if it's a folder name - folders can't be opened
            Case Else
                MsgBox Err.Description, vbInformation, "Error #" & Err.Number
        End Select
        Resume IsLockedExit
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width