Page 1 of 1

Avoid error message accessing CD-ROM

Posted: 19 May 2016 17:08
by LittleBiG
When I try to reach a CD-ROM, and there is no disc in it I always receive an error message which interrupts my scripts. I can use nor folderreport() neither get("freespace"). How can I check this in advance?

For example, I wanted to get the free space on all drives. I could get the drive list by get("drives"), but when was in the foreach loop, the script sowed an error message at the CD-ROM. :-(

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 17:34
by highend
Get the list of CD-Rom drives as well (get("drives", 5)) and in the loop check if that's the current loop item -> continue;

or as an alternative get the drives (fixed + removable) only...

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 21:04
by LittleBiG
But I would like to get info if there is a disc in the CD-ROM, instead of skip it completely. I just want to skip if no disc in it.

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 21:29
by highend
As a workaround get the drivename (get("drivename", $drive))

When it's not like the default (you have to define it first) there is a disc in it and you can use one of your other commands.
Works on PC's where you know the name of the drive...

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 21:52
by highend
And if this isn't enough, you can always use runret() and define a query with wmic

E.g.: wmic cdrom <driveletter:> get medialoaded

returns TRUE / FALSE. Parse the output

But don't forget, the drive needs to spin up and the whole process can last a few seconds until this command returns (if a cd is inserted and the drive isn't spinning)

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 22:04
by LittleBiG
Good ideas, they can help me, thank you!

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 22:06
by TheQwerty
Have you tried testing if the drive exists before calling folderreport?

Re: Avoid error message accessing CD-ROM

Posted: 19 May 2016 22:11
by highend
I have no DVD-Burner any more (who needs CDs/DVDs nowadays?) so yeah, the easiest solution (exists($drive)) should work :)

Re: Avoid error message accessing CD-ROM

Posted: 20 May 2016 12:34
by LittleBiG
Embarrassingly simple. Thank you!