Rafael:
Here is code I use to determine if a user has a flash drive installed in their 
box and if it has the correct volume label. This volume label is how I tell if 
the 'correct' flash drive is in place.
Perhaps there will be some useful code in here...
Regards,

Jack Skelley

local i, lcTitle, lcMessage, lnCount
set safety off
wait window "Looking For Data..." nowait
adir(laData_dbf,"*.dbf")
adir(laData_cdx,"*.cdx")
adir(laData_fpt,"*.fpt")
adir(laData_dct,"*.dct")
adir(laData_dcx,"*.dcx")
adir(laData_dbc,"*.dbc")
lnTotal_len = alen(laData_dbf,1) + alen(laData_cdx,1) +  alen(laData_fpt,1) + ;
              alen(laData_dct,1) + alen(laData_dcx,1) + alen(laData_dbc,1)
dimension laData_tables(lnTotal_len, 5)
wait window "Combining All Data..." nowait
acopy(laData_dbf, laData_tables)
lnStart_position = alen(laData_dbf) + 1
acopy(ladata_cdx, laData_tables, 1, alen(laData_cdx), lnStart_position)
lnStart_position = alen(laData_dbf) + alen(laData_cdx) + 1
acopy(ladata_fpt, laData_tables, 1, alen(laData_fpt), lnStart_position )
lnStart_position = alen(laData_dbf) + alen(laData_cdx) + alen(laData_fpt) + 1
acopy(ladata_dct, laData_tables, 1, alen(laData_dct), lnStart_position )
lnStart_position = alen(laData_dbf) + alen(laData_cdx) + alen(laData_fpt) + ;
                   alen(laData_dct) + 1
acopy(ladata_dcx, laData_tables, 1, alen(laData_dcx), lnStart_position )
lnStart_position = alen(laData_dbf) + alen(laData_cdx) + alen(laData_fpt) + ;
                   alen(laData_dct) + alen(laData_dcx) + 1
acopy(ladata_dbc, laData_tables, 1, alen(laData_dbc), lnStart_position )
lnTotal_bytes = 0
lnBytes_backedup = 0
for i = 1 to alen(laData_tables,1)
  if atc("foxuser",laData_tables(i,1)) > 0 then
    loop
  endif
  lnTotal_bytes = lnTotal_bytes + laData_tables(i,2)
endfor
wait window "Total Bytes To Backup..." + transform(lnTotal_bytes, 
"999,999,999,999") timeout 1
wait window "Organizing Data..." nowait
asort(laData_tables)
****DRIVETYPE RETURN CODES
****1 No type 
****2 Floppy disk 
****3 Hard disk 
****4 Removable drive or network drive 
****5 CD-ROM 
****6 RAM disk1
lcBU_drive = "C:\"
lbGot_CF_RAM = .f.    
do case
  case atc("server", sys(0)) > 0 &&server
    do case  &&start with "E" because DevScout Resides on "D" on server
      case drivetype("C") = 3
        lcBackup_folder = "C:\DevScout Data Backup\"
        lcBU_drive = "C:\"
      case drivetype("E") = 3
        lcBackup_folder = "E:\DevScout Data Backup\"
        lcBU_drive = "E:\"
      case drivetype("F") = 3
        lcBackup_folder = "F:\DevScout Data Backup\"
        lcBU_drive = "F:\"
      case drivetype("G") = 3
        lcBackup_folder = "G:\DevScout Data Backup\"
        lcBU_drive = "G:\"
      case drivetype("H") = 3
        lcBackup_folder = "H:\DevScout Data Backup\"
        lcBU_drive = "H:\"
      case drivetype("I") = 3
        lcBackup_folder = "I:\DevScout Data Backup\"
        lcBU_drive = "I:\"
    endcase
  otherwise  &&scout box and looking for CF RAM
    lnNum_drives = 1
    dimension laDrives(1)
    laDrives(1) = "No Drives..."
    for i = 67 to 91  &&start with drive C:
      do case
        case atc("Windows 5.", os(1)) > 0  &&Windows 2000 or XP Pro
          if drivetype(chr(i)) = 2 then  &&floppy...which is CF RAM Drive in 
Windows 2000
            dimension laDrives(lnNum_drives)
            laDrives(lnNum_drives) = chr(i) + ":\"
            lnNum_drives = lnNum_drives + 1
          endif
        otherwise   &&Windows 98 or ME 
          if drivetype(chr(i)) = 3 then  &&harddisk...which is CF RAM Drive in 
Win9x
            dimension laDrives(lnNum_drives)
            laDrives(lnNum_drives) = chr(i) + ":\"
            lnNum_drives = lnNum_drives + 1
          endif
      endcase 
    endfor
    if laDrives(1) <> "No Drives..." then
      DECLARE INTEGER GetVolumeInformation IN Win32API AS GetVolInfo ;
              STRING  @lpRootPathName, ;
              STRING  @lpVolumeNameBuffer, ;
              INTEGER nVolumeNameSize, ;
              INTEGER @lpVolumeSerialNumber, ;
              INTEGER @lpMaximumComponentLength, ;
              INTEGER @lpFileSystemFlags, ;
              STRING  @lpFileSystemNameBuffer, ;
              INTEGER nFileSystemNameSize
      for i = 1 to alen(laDrives)        
        lpRootPathName           = laDrives(i) && Drive and directory path
        lpVolumeNameBuffer       = SPACE(256) && lpVolumeName return buffer
        nVolumeNameSize          = 256        && Size of/lpVolumeNameBuffer
        lpVolumeSerialNumber     = 0          && lpVolumeSerialNumber buffer
        lpMaximumComponentLength = 256
        lpFileSystemFlags        = 0
        lpFileSystemNameBuffer   = SPACE(256)
        nFileSystemNameSize      = 256
        RetVal=GetVolInfo(@lpRootPathName, @lpVolumeNameBuffer, ;
                          nVolumeNameSize, @lpVolumeSerialNumber, ;
                          @lpMaximumComponentLength, @lpFileSystemFlags, ;
                          @lpFileSystemNameBuffer, nFileSystemNameSize)
        lcVolume = 
LEFT(ALLTRIM(lpVolumeNameBuffer),LEN(ALLTRIM(lpVolumeNameBuffer))-1)
        if atc("data backup", lcVolume) > 0 then
          lcBackup_folder = laDrives(i) + "DevScout Data Backup\"
          lbGot_CF_RAM = .t.        
          exit 
        endif 
      endfor
    endif
    if not lbGot_CF_RAM then
      lcBackup_folder = "C:\DevScout Data Backup\"  &&no CF RAM found so put on 
C:
      if not used('s_system') then
        use s_system in 0
      endif
      select s_system
      replace s_system.s_misc_n3 with 0 &&reset counter to 0
      close databases all  &&close the tables
    endif
endcase 
* 
if not directory((lcBackup_folder)) then
  wait window "Making A BackUp Folder..." nowait
  mkdir((lcBackup_folder))
endif
*
if not lbGot_CF_RAM then 
  do backuphd.fxp   &&backup to hdd as well on every tenth start of the system; 
resets to 0 in this prg...
  return
endif 
*wait window "Erasing Old Backup Files..." nowait   &&Backup files are no 
longer erased to keep old files intact
*dimension laOld_data(1)                            &&Current tables will be 
over written on the backup device 
*laOld_data(1) = "No Data In Folder..."
*adir(laOld_data, lcBackup_folder + "*.*")
*if laOld_data(1) <> "No Data In Folder..." then
*  for i = 1 to alen(laOld_data,1)
*    lcFile = lcBackup_folder + alltrim(laOld_data(i,1))
*    erase (lcFile)
*  endfor
*endif
wait window "Copying Current Data To BackUp Folder..." nowait
lnPercent_done = 0
if lbGot_CF_RAM then  &&will backup data to the CF RAM CARD ONLY 07/23/2009
  for i = 1 to alen(laData_tables,1)
    if atc("foxuser",laData_tables(i,1)) > 0 then
      loop
    endif
    do case
      case lbGot_CF_RAM &&CF RAM card found in box        
        wait window "Copying Current Data To BackUp Folder...Copying " + ;
                    alltrim(laData_tables(i,1)) + " To Memory Card..." + 
chr(13) + chr(10) + ;
                    "Percentage Complete..." + transform(lnPercent_done, "99%") 
nowait
      otherwise &&No CF RAM card found in box so backup to a harddrive folder   
     
        wait window "Copying Current Data To BackUp Folder...Copying " + ;
                    alltrim(laData_tables(i,1)) + " To Hard Disk Drive " + 
lcBU_drive + "..." + chr(13) + chr(10) + ;
                    "Percentage Complete..." + transform(lnPercent_done, "99%") 
nowait
    endcase                
    lcSource = alltrim(laData_tables(i,1))
    lcDestination = lcBackup_folder + alltrim(laData_tables(i,1))
    if drive_ready(justdrive(lcBackup_folder)) then
      from_error = .f.  &&lcBackup_folder
      copy file (lcSource) to (lcDestination)
      if from_error then
        if lbGot_CF_RAM then
          wait window "BackUp Failed...Memory Card Removed or Memory Card Is 
Full..." timeout 3
        else
          wait window "BackUp Failed...Hard Drive Is Defective Or It Is 
Full..." timeout 3
        endif
        exit
      endif
    else
      from_error = .t.  &&force the error flag
      if lbGot_CF_RAM then
        wait window "BackUp Failed...Memory Card Removed or Memory Card Is 
Full..." timeout 3
      else
        wait window "BackUp Failed...Hard Drive Is Defective Or It Is Full..." 
timeout 3
      endif
      exit
    endif
    lnBytes_backedup = lnBytes_backedup + laData_tables(i,2)
    lnPercent_done = int((lnBytes_backedup / lnTotal_bytes) * 100)
  endfor
endif 
*
if atc("server", sys(0)) = 0 then &&not on the server
  if lbGot_CF_RAM then  &&only backup here if data went to CF RAM
    if not used('s_system') then
      use s_system in 0
    endif
    select s_system
    replace s_system.s_misc_n3 with s_system.s_misc_n3 + 1
    lnCount = s_system.s_misc_n3
    close databases all  &&close the table
    if lnCount >= 10 then 
      wait clear
      lcTitle = "Copy Data Files To HardDrive..."
      lcMessage = "You have started the scouting system 10 times and a backup 
to your hard drive will now also occur." + chr(13)
      lcMessage = lcMessage + "It has been determined that an automatic backup 
to your hard drive every tenth start of the system "
      lcMessage = lcMessage + "gave a bit more flexibility in restoring your 
data should your Memory Card (or MemoryStick) data "
      lcMessage = lcMessage + "was found to be corrupted or incomplete." + 
chr(13)
      lcMessage = lcMessage + "If you selected (requested) a hard disk backup 
or removed the Memory Card (MemoryStick) before starting "
      lcMessage = lcMessage + "the system the counter that keeps track of the 
backup sequence will be reset to zero (0)." + chr(13) + chr(13)
      lcMessage = lcMessage + "The backup process to your hard drive is much 
faster then the Memory Card..."
      do form timer_message.scx with lcTitle, lcMessage, 15   &&title or form, 
message displayed, seconds to show
      do backuphd.fxp   &&backup to hdd as well on every tenth start of the 
system; resets to 0 in this prg...
    endif
  endif
endif
*
set safety on
wait clear
return
*******************************************************************************************************************************
*******************************************************************************************************************************
*******************************************************************************************************************************
function drive_ready
  parameter lcDrive
  if diskspace(lcDrive) > 0
    return .t.
  else
    return .f.
  endif
endfunc
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/0b957900b2b8194d998a441195b6603838f2b1e...@drdsrv03.drdad.thenewarkarena.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to