AutoHotkey Community

It is currently May 27th, 2012, 11:57 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: USB auto backup problem
PostPosted: October 31st, 2010, 4:58 am 
Offline

Joined: November 29th, 2009, 7:53 am
Posts: 46
Location: Queensland
i have looked on the forums and found a few different USB backup utilities but not quite what i wanted so i have adapted one of them into this script
Code:
#Noenv
#Persistent

backup=%A_Desktop%\USB_Backup
FileCreateDir,%backup%
DriveGET, USB, List, REMOVABLE
settimer, check, 1000
return

check:
ret := scan4NewDrivesDrives(USB)

If (!ret)
{
   ;nothing here
}
else
{
   msgbox Found New device! : %ret%  ;here you can add code, wich should be executet if a NewDrives USB Device is plugged in.
   DriveGet,SN, Serial, %ret%:
   USB_DIR = %backup%\%SN%
   MsgBox,4, USB Backup, Do You want %ret% to be backed up
   IfMsgBox,YES
   {
      FileCreateDir,%USB_DIR%
      FileCopyDir, %ret%:, %USB_DIR%,1
      if Errorlevel <> 0
      {
         FileCopy, %ret%:, %USB_DIR%,1
         Failed:=ErrorLevel
         Loop, %ret%:\*.*,2
         {
            FileCopyDir, %A_LoopFileFullPath%, %USB_DIR%\%A_LoopFileName%,1
            Failed+=ErrorLevel
         }
      }
      Msgbox, , USB Backup, %ret% backed up to  %USB_DIR%
   }
}
return

scan4NewDrivesDrives(byref olddrives)
{
   DriveGET, NewDrives, List, REMOVABLE
   Loop, parse, NewDrives
   {
      if InStr(olddrives, a_loopfield)
      {
         ;still here
         continue
      }
      else
      {
         ;found New device!
         olddrives := NewDrives ;update
         return, % a_loopfield
      }
      olddrives := NewDrives ;update
      return, 0 ;no New devices found.
   }
}

PROBLEM: Code doesn't register flashdrive being removed
how do i do this


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group