Results 1 to 13 of 13

Thread: [RESOLVED] file exists

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Resolved [RESOLVED] file exists

    i'm trying to see if a user inserted the correct cd. i'm doing this by checking if a file exists on the cd drive. my question is, can i use wildcard characters to see if a file exists? example:

    Code:
    If fso.FileExists("D:\*.cde") = True Then MsgBox "yes"
    this doesn't seem to work. if i enter the complete file name, it works.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: file exists

    If Dir("D:\*.cde") > vbNull Then MsgBox "yes"
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: file exists

    type mismatch

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: file exists

    vbNullString would work a little better.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: file exists

    thanks.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: file exists

    You are welcome.

    If you consider this resolved, you could help us out by pulling down the Thread Tools menu and click the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

    Thank you.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: file exists

    if there is no cd in the drive at all i get an error message. how can i check if there is a cd in the drive?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: file exists

    Why not just trap for the error?

    What is the error number you get?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: file exists

    Run-time error '52'
    Bad file name or number

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: file exists

    vb Code:
    1. On Error GoTo ErrTrap
    2. 'your file exists code
    3. Exit Sub
    4. ErrTrap:
    5. If Err.Number = 52 Then
    6.    Msgbox "Please insert a CD into the CD Drive.",vbOKOnly + vbInformation,"No CD"
    7. Else
    8.    Msgbox Err.Number & " " & Err.Description
    9. End If
    10. End Sub

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: file exists

    works great. one last question. is there a way to automatically eject the cd?

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: file exists

    Try
    vb Code:
    1. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
    2. (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
    3. ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    4.  
    5. Private Sub cmdOpenCD_Click()
    6. Dim OpenCDDrive As Long
    7. OpenCDDrive = mciSendString("set CDAudio door open", "", 127, 0)
    8. End Sub

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: file exists

    thanks. thanks. thanks.

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