Avoid error message accessing CD-ROM

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Avoid error message accessing CD-ROM

Post 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. :-(

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Avoid error message accessing CD-ROM

Post 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...
One of my scripts helped you out? Please donate via Paypal

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Avoid error message accessing CD-ROM

Post 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.

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Avoid error message accessing CD-ROM

Post 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...
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Avoid error message accessing CD-ROM

Post 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)
One of my scripts helped you out? Please donate via Paypal

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Avoid error message accessing CD-ROM

Post by LittleBiG »

Good ideas, they can help me, thank you!

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Avoid error message accessing CD-ROM

Post by TheQwerty »

Have you tried testing if the drive exists before calling folderreport?

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Avoid error message accessing CD-ROM

Post by highend »

I have no DVD-Burner any more (who needs CDs/DVDs nowadays?) so yeah, the easiest solution (exists($drive)) should work :)
One of my scripts helped you out? Please donate via Paypal

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Avoid error message accessing CD-ROM

Post by LittleBiG »

Embarrassingly simple. Thank you!

Post Reply