skipping empty drives with 'Windows Script Host' Automation

BluefingerBluefinger Member Posts: 20
Hi,

I have written a routine where I am scanning all hard drives for a certain folder (DCIM), so I can find out which drive is the flash card reader. This works quite nicely but I get an error message saying that the drive is empty for every drive that exists but, well ... is empty ... like empty CD-ROM drives or empty card reader slots. Is there a way to scan these without getting the error message?

here's the code:
FOR i := 4 TO 25 DO BEGIN                     
  Chr := i + 64;
  ImportDrive := FORMAT(Chr);
  IF WinScriptHost.FolderExists(ImportDrive + ':\DCIM') THEN
    ImportPath := ImportDrive + ':\DCIM';
END;

thanks!

Comments

  • klavinklavin Member Posts: 117
    You could do something along the lines of:
    //declare automations for Drives and Drive
    WshDrives := WshFSO.Drives();
    WshDrive := WshDrives.Item(DriveLetter);
    MESSAGE(FORMAT(WshDrive.IsReady())); //will tell you if the drive is ready (media inserted)
    
    //declare DriveType integer
    //To identify the drive type beforehand:
    
      DriveType := WshDrive.DriveType();
      CASE DriveType OF
        0 : MESSAGE('Unknown');
        1 : MESSAGE('Removable');
        2 : MESSAGE('Fixed');
        3 : MESSAGE('Network');
        4 : MESSAGE('CD-ROM');
        5 : MESSAGE('RAM Disk');
      END;
    
    

    Though if I choose a removable drive, or even CDROM and do IF NOT WshFSO.FolderExists('D:\DCIM') MESSAGE('Does not exist'); I don't get any errors even with empty media.

    Take a look at the above options, you can identify removable drives and check if they are in a ready state prior to making the call. Obviously you wouldn't use messages, but those are the types.

    Kevin
    -Lavin
    "Profanity is the one language all programmers know best."
  • BluefingerBluefinger Member Posts: 20
    Thanks a lot, I'll try that.

    For some strange reason I do not get these error-messages all the time. With the same codeunit, sometimes the empty drives are ignored, sometimes they produce error messages and I haven't found out why yet.
  • BluefingerBluefinger Member Posts: 20
    Ok, it works perfectly now. I had to insert this first:
    IF WSHFSO.DriveExists(DriveLetter) THEN BEGIN
    

    ... because if I checked on a non existent drive with ISREADY I got another error message. Now it works like a charm ... thanks!
Sign In or Register to comment.