closeupman Posted January 25, 2005 Posted January 25, 2005 tells whether u have an audio cd in your cd-rom drive.My 1st function I'm posted here, hope you find it useful.Made it in response to a user request. tested it and it worked fine. Only glitch I can see is if you insert a cd b4 you run it and run it right away it won't work. you have to let the computer "get up to date" (i.e. wait till that loading light is off"...you can just put a sleep in your main code if you want..i've also added another func to let u decide which you like to use better.The first one just says whether there is a audio cd in ANY cd-rom drive.The 2nd one lets you send it a drive (format eg. e: NO backslash) and tell you whether THAT drive has an audio cd in it.(w/ example) The global const's are NEEDED by the function, so make sure you have them in your program.ENJOY expandcollapse popupGlobal const $TRUE=1 Global const $FALSE=0 local $findAudio $findAudio=_IsAudioCD() if $findAudio then msgbox(0,"","You have an Audio CD in your cd-rom") Func _IsAudioCD() ;search through all the drives to find a cd rom drive, ;then see if it has an audio cd in there. ; TRUE = found audio cd ; FALSE = didn't find audio cd, or user doesn't have a cd-rom drive ;get all CDROM drives $var = DriveGetDrive( "CDROM" ) ;if we found 1 or more cdrom drives then check if there's an ;audio cd in any of them If NOT @error Then For $i = 1 to $var[0] ;change the path ---- used to tell FileFindFirstFile where to search ;change it to our cd-rom FileChangeDir ( $var[$i]&"\" ) ; if find a .cda file then means we got an audio cd $search = FileFindFirstFile("*.cda") ; Check if the search was successful ; return appropriate value as specified in func description If $search = -1 Then Return $FALSE Else Return $TRUE EndIf Next Else return $FALSE EndIf EndFunc Func _IsAudioCdDrive($drive) ;$drive MUST be only drive w/colon otherwise causes error FileChangeDir ( $drive &"\" ) ; if find a .cda file then means we got an audio cd $search = FileFindFirstFile("*.cda") ; Check if the search was successful ; return appropriate value as specified in func description If $search = -1 Then Return $FALSE Else Return $TRUE EndIf EndFuncaudiocd.au3
DirtyBanditos Posted January 25, 2005 Posted January 25, 2005 (edited) tells whether u have an audio cd in your cd-rom drive.My 1st function I'm posted here, hope you find it useful.Made it in response to a user request. tested it and it worked fine. Only glitch I can see is if you insert a cd b4 you run it and run it right away it won't work. you have to let the computer "get up to date" (i.e. wait till that loading light is off"...you can just put a sleep in your main code if you want..i've also added another func to let u decide which you like to use better.The first one just says whether there is a audio cd in ANY cd-rom drive.The 2nd one lets you send it a drive (format eg. e: NO backslash) and tell you whether THAT drive has an audio cd in it.(w/ example) The global const's are NEEDED by the function, so make sure you have them in your program.ENJOY expandcollapse popupGlobal const $TRUE=1 Global const $FALSE=0 local $findAudio $findAudio=_IsAudioCD() if $findAudio then msgbox(0,"","You have an Audio CD in your cd-rom") Func _IsAudioCD() ;search through all the drives to find a cd rom drive, ;then see if it has an audio cd in there. ; TRUE = found audio cd ; FALSE = didn't find audio cd, or user doesn't have a cd-rom drive ;get all CDROM drives $var = DriveGetDrive( "CDROM" ) ;if we found 1 or more cdrom drives then check if there's an ;audio cd in any of them If NOT @error Then For $i = 1 to $var[0] ;change the path ---- used to tell FileFindFirstFile where to search ;change it to our cd-rom FileChangeDir ( $var[$i]&"\" ) ; if find a .cda file then means we got an audio cd $search = FileFindFirstFile("*.cda") ; Check if the search was successful ; return appropriate value as specified in func description If $search = -1 Then Return $FALSE Else Return $TRUE EndIf Next Else return $FALSE EndIf EndFunc Func _IsAudioCdDrive($drive) ;$drive MUST be only drive w/colon otherwise causes error FileChangeDir ( $drive &"\" ) ; if find a .cda file then means we got an audio cd $search = FileFindFirstFile("*.cda") ; Check if the search was successful ; return appropriate value as specified in func description If $search = -1 Then Return $FALSE Else Return $TRUE EndIf EndFunc<{POST_SNAPBACK}>Hello great job! Edited January 25, 2005 by DirtyBanditos
closeupman Posted January 26, 2005 Author Posted January 26, 2005 Hello great job! <{POST_SNAPBACK}>Thanks I updated my code audiocdv1point3.au3Made it one function, also I put my const's inside my function, so if you don't like to use them u don't have to(though $TRUE & $FALSE can come in handy in many places and much easier to debug).The return value of the function is still the same, however you put a variable to receive the drive letter which will be returned with the function call if it is true. You DON'T have to specify anything. It is only there to RECEIVE a value.expandcollapse popup;used for demonstration purposes only local $foundAudioAudio,$thisdrive ;DEMO USE of Function $foundAudioCD=_IsAudioCD($thisdrive) if $foundAudioCD then msgbox(0,"","You have an Audio CD in your " &$thisdrive&" drive") Func _IsAudioCD(ByRef $whatdrive) ;search through all the drives to find a cd rom drive, ;then see if it has an audio cd in there. ; TRUE = found audio cd, ; and returns the drive letter of the drive that had the audio cd in $whatdrive ; FALSE = didn't find audio cd, or user doesn't have a cd-rom drive ;used for return values Local const $TRUE=1 Local const $FALSE=0 ;get all CDROM drives $var = DriveGetDrive( "CDROM" ) ;if we found 1 or more cdrom drives then check if there's an ;audio cd in any of them If NOT @error Then For $i = 1 to $var[0] ;change the path ---- used to tell FileFindFirstFile where to search ;change it to our cd-rom FileChangeDir ( $var[$i]&"\" ) ; if find a .cda file then means we got an audio cd $search = FileFindFirstFile("*.cda") ; Check if the search was successful ; return appropriate value as specified in func description If $search = -1 Then Return $FALSE Else ;return what drive the Audio CD was in ;and let user know we found an Audio CD ($TRUE) $whatdrive=StringUpper(StringLeft($var[$i],1)) Return $TRUE EndIf Next Else return $FALSE EndIf EndFunc
DirtyBanditos Posted January 26, 2005 Posted January 26, 2005 Thanks I updated my code audiocdv1point3.au3Made it one function, also I put my const's inside my function, so if you don't like to use them u don't have to(though $TRUE & $FALSE can come in handy in many places and much easier to debug).The return value of the function is still the same, however you put a variable to receive the drive letter which will be returned with the function call if it is true. You DON'T have to specify anything. It is only there to RECEIVE a value.expandcollapse popup;used for demonstration purposes only local $foundAudioAudio,$thisdrive ;DEMO USE of Function $foundAudioCD=_IsAudioCD($thisdrive) if $foundAudioCD then msgbox(0,"","You have an Audio CD in your " &$thisdrive&" drive") Func _IsAudioCD(ByRef $whatdrive) ;search through all the drives to find a cd rom drive, ;then see if it has an audio cd in there. ; TRUE = found audio cd, ; and returns the drive letter of the drive that had the audio cd in $whatdrive ; FALSE = didn't find audio cd, or user doesn't have a cd-rom drive ;used for return values Local const $TRUE=1 Local const $FALSE=0 ;get all CDROM drives $var = DriveGetDrive( "CDROM" ) ;if we found 1 or more cdrom drives then check if there's an ;audio cd in any of them If NOT @error Then For $i = 1 to $var[0] ;change the path ---- used to tell FileFindFirstFile where to search ;change it to our cd-rom FileChangeDir ( $var[$i]&"\" ) ; if find a .cda file then means we got an audio cd $search = FileFindFirstFile("*.cda") ; Check if the search was successful ; return appropriate value as specified in func description If $search = -1 Then Return $FALSE Else ;return what drive the Audio CD was in ;and let user know we found an Audio CD ($TRUE) $whatdrive=StringUpper(StringLeft($var[$i],1)) Return $TRUE EndIf Next Else return $FALSE EndIf EndFunc<{POST_SNAPBACK}> Hello great and thx you for the update) I share it out on my forum for any Newbie to learn from it!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now