Yrmann said:
It will be annoying for the users,to begin with
Did you already change it and got feedback?
I had to empty a thumbdrive to check this, the actual problem is, that the normal VFP GETDIR() dialog sticks to the drive it currently shows, when there are no folders or files in the other drive at all. Also: Even if you know an empty drive and SET DEFA to it, the GETDIR dialog will switch back to C:\ or the first drive with files/folders on it. It really avoids empty drives, what a bug.
You could use this code, which would detect USB drives and add a dummy getdir.txt file, if no single file/folder is found on such a drive. When I run this with my empty USB drive attached it generates getdir.txt with 0 bytes. That should even be possible on a full drive, as a 0 byte file only needs a place in the TOC (table of contents) of the file system that reserves place anyway. Well, and for the purpose of a backup you'll want to assure there's enough free disk space anyway. If any file or folder is found on a drive they are untouched, this code does not write "getdir.txt" to any drive letter with drivetype 2, only those making problems with GETDIR() by being ewmpty.
Code:
Local lnDrive, lcDrive
For lnDrive= 3 To 26 && avoid 'A:\ and 'B:\'
lcDrive = Chr(64+lnDrive)+':\'
If DriveType(m.lcDrive)=2 && floppy disk , USB drive-
If Empty(Sys(2000,m.lcDrive+'*.*'))
StrToFile('',m.lcDrive+'getdir.txt')
Endif
EndIf
EndFor
Your mileage might vary slightly. Because...
1. In my test DriveType() for my USB thumbdrive was 2, which by documentation means floppy disk. Watch out, if you really have a floppy disk drive just like other removable drive types, including CD/DVD/BD. Checking for files on them with SYS(2000) while no disk/sd card, CD/DVD/BD is inserted could lead to errors or long timeouts, which are even worse. Therefore not any drivetype>1 is good to go, some USB drives might also be drivetype 4, though, not sure.
2. I start at Drive C:\ (lnDrivce=3), to avoid legacy A:\, B:\ floppy disk, drivetype 2 seems to be legit for USB drives with letters C: or above, check with your own USB drives, perhaps. You might also start at D:\ and assume C:\ will always be the OS hard drive, though there are unusual setups with some thin client computers.
As GETDIR() won't show any filenames, that trick remains unseen, especially if you care for deleting the file again, after GETDIR(), no matter what drive/directory the user picks. To be able to know that, I would build a list of the generated files after each STRTOFILE() to finally remove them, again. But erasing the files can't be done in this code, it has to be done separately after GETDIR(), of course. I spared to implement that whole aspect, if you care for it, you could also leave the empty text file.
This could also be done with a WMI query for Win32_USBControllerDevice, but this is overkill and would require diving deeper into differentiating between USB drives and other USB devices, using DriveType() keeps things easy.
Chriss