Jump to content

FindCD function


MHz
 Share

Recommended Posts

I have just expanded on my FindCD function. I consider it reasonably foolproof at the moment, until proven otherwise. Just thought I would share it with others. :idiot:

Task of Function. To locate the drive letter for a certain CD, whether by title or by a filename in the root of the CD.

; Example use
$result = _FindCD("setup.exe", 0)
MsgBox(0, "", $result)

Func _FindCD($name, $option)
    ; e.g. _FindCD('Setup.exe', 0) or _FindCD('CD Title', 1)
    ; $option: 0 = Filename in CD Root; 1 = CD title
    Local $allocated, $drives
    While Not $allocated
        $drives = DriveGetDrive('CDROM')
        If Not @error Then
            For $i = 1 To $drives[0]
                If DriveStatus($drives[$i] & '\') = 'READY' Then
                    If $option = 0 Then
                        If FileExists($drives[$i] & '\' & $name) Then
                            $allocated = $drives[$i]
                            Return $allocated
                        EndIf
                    ElseIf $option = 1 Then
                        $allocated = $drives[$i]
                        If DriveGetLabel($allocated) = $name Then
                            Return $allocated
                        EndIf
                    EndIf
                EndIf
            Next
            If Not $allocated Then
                If MsgBox(5 + 16, 'Warning', 'Please insert CD into a drive now') = 2 Then
                    Sleep(1000)
                    If MsgBox(4 + 32, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
                EndIf
                Sleep(2000)
            EndIf
        EndIf
    WEnd
EndFunc

Edit: updated functions.

Edit: updated to autoit tags

Edit: fixed mess with AutoIt tags

Edited by MHz
Link to comment
Share on other sites

  • 12 years later...

This script works great, but i'm struggling on how to get it to work with a partial DVD name.
I think I need to set a StringInStr somewhere, but don't know where to put it inside of the function.

I have DVD's with a different name for each DVD except for the last part of the name, e.g.:

  • 0117ABCD
  • 0217ABCD
  • 0317ABCD

How can I validate against the ABCD part of a DVD name?

P.S. Sorry for the old thread bump

Link to comment
Share on other sites

12 hours ago, WatskeBart said:

P.S. Sorry for the old thread bump

The preferred practice with topics this old, is that you start a new topic and add a link back to the old one in it.

Usually code has changed over AutoIt versions, especially a lot since 2004.

It is not entirely clear to me what you are wanting to do, so perhaps whip up some code of your own (even if bits don't work yet) to give us a little greater understanding of what you want. Comments in certain places can be helpful too.

As for getting a unique return for the Label/Name, you could do a Replace on it, leaving just the bit that is different.
 

$label = "0117ABCD"
$uniqueID = StringReplace($label, "ABCD", "")
MsgBox(0, "Unique DVD ID", $uniqueID)

P.S. Welcome to the forum. :)

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Thank you for the quick reply and the warm welcome.

I come from a age where starting a new thread was not done, when there's still a old one ^_^

 

I already figured out my problem by doing the following.

Changed this code:

ElseIf $option = 1 Then
       $allocated = $drives[$i]
          If DriveGetLabel($allocated) = $name Then
             Return $allocated
          EndIf
EndIf

To this code:

ElseIf $option = 1 Then
       $allocated = $drives[$i]
       $label = DriveGetLabel($allocated)       ;Put the output into $label, which contains 0117ABCD
          If StringInStr($label, $name) Then    ;Check if part of $label contains $name, which in my case would be ABCD
             Return $allocated
          EndIf
EndIf

I also edited If Not $allocated part, because when using option 1, it will return 0 when no match is found.

So this:

If Not $allocated Then

Turned into this:

If Not $allocated Or $allocated = 0 Then

 

Again thank you for the quick reply, and I will make a new thread the next time.

 

//WB

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...