skipping empty drives with 'Windows Script Host' Automation

Bluefinger
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:
thanks!
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!
0
Comments
-
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."0 -
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.0 -
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!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions