Copy file(s) to variable usb stick station

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Copy file(s) to variable usb stick station

30 May 2020, 04:38

I've got an raspberry pi 4, i need to copy files to any usb drive i put in my pc, now i have to manualy open 'my computer',open the usb drive letter and copy files.

Is there a way to do a copy script to a usb stick which i put in my pc?
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

30 May 2020, 05:52

Thanx for the reply, but i am not a programmer, so i couldn't get this to work like asked earlier
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

30 May 2020, 18:07

Can't nobody help me with this?
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Copy file(s) to variable usb stick station

30 May 2020, 20:26

First you have to know which letter the USB Disk using.
Then you can use FileCopy() like it is documented here https://www.autohotkey.com/docs/commands/FileCopy.htm
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

31 May 2020, 03:07

Smile_ wrote:
30 May 2020, 20:26
First you have to know which letter the USB Disk using.
Then you can use FileCopy() like it is documented here https://www.autohotkey.com/docs/commands/FileCopy.htm
But how can autohotkey detect which drive it suppose to write the files to?

I like to put in a drive and autohotkey detects when i activate filecopy to do it's work
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Copy file(s) to variable usb stick station

31 May 2020, 06:10

example with filecopy or robocopy
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=76064

Detect USB drive from user 'teadrinker'
https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

example shows last drive , I usually copy from secondlast to lastdrive ( example D > E )

Code: Select all

;-------- saved at Sonntag, 31. Mai 2020 13:07:14 --------------
;- Detect Usb Drive 
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

drivegetshow:
i=0
alldrives:=""
DriveGet, A, List,
StringSplit,D, A,
loop,%d0%
{
DRV:= % d%a_index% . ":\"
i++
      DriveGet       , type1   , type     , %DRV%     ;- removable / fixed
      DriveGet       , cap1    , capacity , %DRV%
      DrivespaceFree , free1   ,            %DRV%
      DriveGet       , fs1     , fs       , %DRV%     ;- FAT
      DriveGet       , label1  , label    , %DRV%     ;- volume label >\\server1
      DriveGet       , serial1 , serial   , %DRV%     ;- volume serial number
      DriveGet       , status1 , status   , %DRV%
alldrives .= drv . "  " . type1 . "  " . free1 . "-MB`n"
;msgbox, 262208,Drive-Info_%i% ,%DRV%  %type1%  %label1%  %fs1%  %cap1%-MB  %free1%-MB  %status1% %serial1%
lastdrive_info=%DRV%  %type1%  %label1%  %fs1%  %cap1%-MB  %free1%-MB  %status1%  Nr=%serial1%
}
VT:=D0       ;- totaldrives
VL:=(D0-1)   ;- totaldrives-1
last         = %drv%
loop,%vl%
 seclast    := d%a_index% . ":\"
msgbox, 262208,Info ,Alldrives=`n%alldrives%`nSECLAST=%seclast%`nLAST=%last%`n----------------`nLastdrive_Info=`n%lastdrive_info%
return
;esc::exitapp
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

31 May 2020, 09:34

garry wrote:
31 May 2020, 06:10
example with filecopy or robocopy
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=76064

Detect USB drive from user 'teadrinker'
https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

example shows last drive , I usually copy from secondlast to lastdrive ( example D > E )

Code: Select all

;-------- saved at Sonntag, 31. Mai 2020 13:07:14 --------------
;- Detect Usb Drive 
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

drivegetshow:
i=0
alldrives:=""
DriveGet, A, List,
StringSplit,D, A,
loop,%d0%
{
DRV:= % d%a_index% . ":\"
i++
      DriveGet       , type1   , type     , %DRV%     ;- removable / fixed
      DriveGet       , cap1    , capacity , %DRV%
      DrivespaceFree , free1   ,            %DRV%
      DriveGet       , fs1     , fs       , %DRV%     ;- FAT
      DriveGet       , label1  , label    , %DRV%     ;- volume label >\\server1
      DriveGet       , serial1 , serial   , %DRV%     ;- volume serial number
      DriveGet       , status1 , status   , %DRV%
alldrives .= drv . "  " . type1 . "  " . free1 . "-MB`n"
;msgbox, 262208,Drive-Info_%i% ,%DRV%  %type1%  %label1%  %fs1%  %cap1%-MB  %free1%-MB  %status1% %serial1%
lastdrive_info=%DRV%  %type1%  %label1%  %fs1%  %cap1%-MB  %free1%-MB  %status1%  Nr=%serial1%
}
VT:=D0       ;- totaldrives
VL:=(D0-1)   ;- totaldrives-1
last         = %drv%
loop,%vl%
 seclast    := d%a_index% . ":\"
msgbox, 262208,Info ,Alldrives=`n%alldrives%`nSECLAST=%seclast%`nLAST=%last%`n----------------`nLastdrive_Info=`n%lastdrive_info%
return
;esc::exitapp
Thanx :) i looked at it, and i can understand how this works (somewhat :p) but usb drive is variable, i've got tons of usb drives and all of them use another drive letter (at least most of them)

is it possible to detect the usb drive and copy 1 or more files to it from ssd -> variable usb drive
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Copy file(s) to variable usb stick station

31 May 2020, 11:15

example your SSD is C:\
-1-Start this script
-2-connect your USB and see LastDrive > D:\ ( or maybe X:\ )
-3-asked : "Want you COPY = C:\TEST to D:\_BEELINK_2\TEST ? (Y/N )
can you check if this works ?

Example :
SOURCE= C:\TEST
DEST =%last%_BEELINK_2\TEST

Code: Select all

;- Copy file(s) to variable usb stick station 
;- https://www.autohotkey.com/boards/viewtopic.php?p=332640#p332640

;- Detect Usb Drive  ( from user 'teadrinker' )
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

#warn
#NoEnv
#Singleinstance,force
Setworkingdir,%a_scriptdir%
OnMessage(0x219, "WM_DEVICECHANGE")
return
;----------------------------
EventHandler(letter, event)
{
if event
   {
   gosub,drivegetshow 
   gosub,aa
   return
   }
   else
     return
}
;----------------------------

aa:
;-----------
;source1=%a_desktop%                  ;
source1=C:\TEST
dest1  =%last%_BEELINK_2\TEST  ;
;----------
msgbox, 262436,COPY-TEST,%alldrives%`n-------------`nLastdrive_Info=`n%lastdrive_info%`n==================`nWant you COPY =`n%source1% >>>`n%dest1% ?
   IfMsgBox,No
       Exitapp
runwait,%comspec% /k robocopy "%source1%" "%dest1%" /XO /E /TEE /UNICODE
msgbox, 262208, ,COPY ended`nSOURCE=%source1%`nDEST=%dest1%
exitapp
;-------------
drivegetshow:
i=0
alldrives:=""
DriveGet, A, List,
StringSplit,D, A,
loop,%d0%
{
DRV:= % d%a_index% . ":\"
i++
      DriveGet       , type1   , type     , %DRV%     ;- removable / fixed
      DriveGet       , cap1    , capacity , %DRV%
      DrivespaceFree , free1   ,            %DRV%
      DriveGet       , fs1     , fs       , %DRV%     ;- FAT
      DriveGet       , label1  , label    , %DRV%     ;- volume label >\\server1
      DriveGet       , serial1 , serial   , %DRV%     ;- volume serial number
      DriveGet       , status1 , status   , %DRV%
alldrives .= drv . "  " . type1 . "  " . free1 . "-MB`n"
;msgbox, 262208,Drive-Info_%i% ,%DRV%  %type1%  %label1%  %fs1%  %cap1%-MB  %free1%-MB  %status1% %serial1%
lastdrive_info=%DRV%  %type1%  %label1%  %fs1%  %cap1%-MB  %free1%-MB  %status1%  Nr=%serial1%
}
VT:=D0       ;- totaldrives
VL:=(D0-1)   ;- totaldrives-1
last         = %drv%
loop,%vl%
 seclast    := d%a_index% . ":\"
;msgbox, 262208,Info ,Alldrives=`n%alldrives%`nSECLAST=%seclast%`nLAST=%last%`n----------------`nLastdrive_Info=`n%lastdrive_info%
return
;------------------------------------

;- Detect Usb Drive  ( from user 'teadrinker' )
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409
/*
EventHandler(letter, event)
{
   MsgBox, % "Drive " . letter . (event ? " has arrived" : " was removed")
}
*/
;------------------
WM_DEVICECHANGE(wp, lp)
{  ;- user 'teadrinker'  https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409
   static DBT_DEVICEARRIVAL := 0x8000, DBT_DEVICEREMOVECOMPLETE := 0x8004, DBT_DEVTYP_VOLUME := 2
   
   if NumGet(lp + 4, "UInt") = DBT_DEVTYP_VOLUME && (wp = DBT_DEVICEARRIVAL || wp = DBT_DEVICEREMOVECOMPLETE) {
      dbcv_unitmask := NumGet(lp + 12, "UInt")
      letter := Chr(Asc("A") + ln(dbcv_unitmask)/ln(2))
      timer := Func("EventHandler").Bind(letter, wp = DBT_DEVICEARRIVAL)
      SetTimer, % timer, -10
   }
}
;=====================================
esc::exitapp
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

31 May 2020, 16:17

Thanx Garry, I will try to explain:

Currently i am enhancing a script which download some files from my Google drive to my desktop (which in w10 is always %A_Desktop% on every w10 pc...

this script should be running on other computer too (only w10) but their last drive isnt always the usb drive, like i have: Y and Z are webdev storages so the usb drive isnt the last drive in this case...

However i will try this script and hopefully i still can use it if there is no other way
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

31 May 2020, 16:28

To add to this:

I've remaped the webdav drives to F and G (ssd drives are C, D and E) when this script is launched and i put the usb drive in it works perfectly, but when the webdev drives are last, the files are copied there.....

so this can help alot but i would prefer it to work only with usb drives
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Copy file(s) to variable usb stick station

31 May 2020, 17:18

can maybe use the drive infos , example if (serial1="12345678") or if (type1="removable") then break the loop and get drive letter ( drv )
;msgbox, 262208,Drive-Info_%i% ,%DRV% %type1% %label1% %fs1% %cap1%-MB %free1%-MB %status1% %serial1%
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: Copy file(s) to variable usb stick station

31 May 2020, 17:33

He seems quite hesitant to check the DriveGet command as BoBo had already suggested at the beginning of this thread?!
Besides that, it shouldn't be a problem to create a "path-pattern" that is specific for that explicit USB-Drive. So to check for that file/folder-structure shouldn't be that tough afterward.

https://autohotkey.com/board/topic/83959-run-program-based-on-usb-pid-vid-eject-and-insert-webcam/

http://www.nirsoft.net/utils/usb_devices_view.html (offers a bunch of command-line options).
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

01 Jun 2020, 02:27

thanx @garry , i will try that :)

@BNOLI i did say i am not a programmer and so i didnt understand the script and how to use it... thats all. I wasnt disrespectfull or unthankful, i even thank him..... every effort given to help me i am thankful, always.
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Copy file(s) to variable usb stick station

01 Jun 2020, 02:47

@BNOLI thank you for the links
@loek6000 here just another short script which checks 2 serialnumbers and if it's READY and REMOVABLE asks to copy
EDIT : added more Info ( drive )

Code: Select all

;- Detect Usb Drive 
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

;- example with filecopy or robocopy
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=76064

;- Detect USB drive from user 'teadrinker'
;- https://www.autohotkey.com/boards/viewtopic.php?t=76221&p=330409

;- links recommended from user BNOLI :
;- https://autohotkey.com/board/topic/83959-run-program-based-on-usb-pid-vid-eject-and-insert-webcam/
;- https://www.nirsoft.net/utils/usb_devices_view.html

#warn
#Noenv
#Singleinstance,force

;--- your USB drives ( REMOVABLE and READY ) with these serialnumbers :
u1:=2593042335
u2:=2680353722

gosub,drivegetshow
;-----------
;source1=%a_desktop%
source1=C:\TEST
dest1  =%DriveXY%_BEELINK_4\TEST
;----------
if (r=1)
  gosub,aa
else
  exitapp
;----------
aa:
msgbox, 262436,COPY-TEST,DRIVE FOUND with Expected Serialnumber`n%Drive_Info%`n=============`nWant you COPY =`n%source1% >>>`n%dest1% ?
   IfMsgBox,No
       Exitapp
runwait,%comspec% /k robocopy "%source1%" "%dest1%" /XO /E /TEE /UNICODE
msgbox, 262208, ,COPY ended`nSOURCE=%source1%`nDEST=%dest1%
exitapp
;----------------
drivegetshow:
R:=0
alldrives:=""
DriveGet, A, List,
StringSplit,D, A,
loop,%d0%
{
DRV:= % d%a_index% . ":\"
DriveGet       , type1   , type     , %DRV%     ;- removable / fixed
DriveGet       , status1 , status   , %DRV%
DriveGet       , serial1 , serial   , %DRV%     ;- volume serial number
;----------
DriveGet       , cap1    , capacity , %DRV%
DrivespaceFree , free1   ,            %DRV%
DriveGet       , fs1     , fs       , %DRV%     ;- FAT
DriveGet       , label1  , label    , %DRV%     ;- volume label >\\server1
;-----------
if (type1="Removable") and (Status1="Ready")
  {
  if ((serial1=u1) or (serial1=u2))
    {
    r:=1
    Drive_Info=Drive=%drv%`nType=%type1%`nStatus=%status1%`nSerial=%serial1%`nFREE=%free1%-MB`nCapacity=%cap1%-MB`nFAT_NTFS=%fs1%`nLabel=%label1%   
    DriveXY= %drv%
    break
    }
  }
}
if (r=0)
 {
 msgbox, 262208, ,No REMOVABLE and READY drive found with expected Serialnumber
 exitapp
 }
return
;esc::exitapp
;=============================================
Last edited by garry on 01 Jun 2020, 05:43, edited 2 times in total.
Eureka
Posts: 65
Joined: 03 Apr 2018, 13:31

Re: Copy file(s) to variable usb stick station

01 Jun 2020, 03:58

The easiest - semi-automatic - way I can think of:
  • Insert your USB-drive or
  • Select the file(s) you want to copy
  • Right-click your selection
  • From the opening context menu, select Send To > your drive
  • Done
loek6000
Posts: 163
Joined: 14 Aug 2019, 17:46

Re: Copy file(s) to variable usb stick station

01 Jun 2020, 05:15

Thanx all :)

I will work with these scripts and try how it works out :)
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Copy file(s) to variable usb stick station

01 Jun 2020, 05:23

@Eureka , dat is juist , maar ...
script is , if you want copy without thinking ... for stupids like me ... I like this automatism and see info about drive... I copy every day the same folders to external drive ( new created or modified )
EDIT : added more info ( drive )

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 82 guests